<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>Debug Description</title>
<title>CMSIS-Pack: Debug Description</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="cmsis.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<script type="text/javascript" src="printComponentTabs.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
  $(window).load(resizeHeight);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 46px;">
  <td id="projectlogo"><img alt="Logo" src="CMSIS_Logo_Final.png"/></td>
  <td style="padding-left: 0.5em;">
   <div id="projectname">CMSIS-Pack
   &#160;<span id="projectnumber">Version 1.6.0</span>
   </div>
   <div id="projectbrief">Delivery Mechanism for Software Packs</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<div id="CMSISnav" class="tabs1">
    <ul class="tablist">
      <script type="text/javascript">
		<!--
		writeComponentTabs.call(this);
		//-->
      </script>
	  </ul>
</div>
<!-- Generated by Doxygen 1.8.6 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li class="current"><a href="pages.html"><span>Usage&#160;and&#160;Description</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('debug_description.html','');});
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Pages</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">Debug Description </div>  </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p>Debug descriptions allow silicon vendors to create tool-agnostic debug and trace configurations so that the development environment settings can be reduced to simple checkboxes for selecting for example either standard run/stop debugging or complex instruction tracing.</p>
<h1><a class="anchor" id="das_concept"></a>
Concept</h1>
<p>A set of standardized debug and trace methods are automatically executed by the debugger:</p>
<ul>
<li>Setting breakpoints and watchpoints</li>
<li>Reading memory and registers</li>
<li>Starting and stopping trace</li>
</ul>
<p>Implementation-specific steps can be described using an XML syntax:</p>
<ul>
<li>Special hardware reset</li>
<li>Trace buffer setup</li>
<li>Patch silicon issues</li>
</ul>
<h1><a class="anchor" id="das_elements"></a>
Debug description elements</h1>
<p>A complete debug description for a device consists of the following elements:</p>
<ul>
<li><a class="el" href="pdsc_family_pg.html#element_debug">debug</a> with the child element <a class="el" href="pdsc_family_pg.html#element_dbg_datapatch">dbg_datapatch</a> contains settings for the debug connection and for fixing silicon issues in software.</li>
<li><a class="el" href="pdsc_family_pg.html#element_debugconfig">debugconfig</a> provides the default debugger configuration for a target connection.</li>
<li><a class="el" href="pdsc_family_pg.html#element_debugvars">debugvars</a> specifies global debug access variables. They can be used in addition to predefined variables in order to query settings from a debug access sequences.</li>
<li><a class="el" href="pdsc_family_pg.html#element_debugport">debugport</a> with the child elements <a class="el" href="pdsc_family_pg.html#element_dp_jtag">dp_jtag</a>, <a class="el" href="pdsc_family_pg.html#element_dp_swd">dp_swd</a>, and <a class="el" href="pdsc_family_pg.html#element_dp_cjtag">dp_cjtag</a> describes the debug port in detail.</li>
<li><a class="el" href="pdsc_family_pg.html#element_sequences">sequences</a> with the child elements <a class="el" href="pdsc_family_pg.html#element_sequence">sequence</a>, <a class="el" href="pdsc_family_pg.html#element_seq_control">seq_control</a>, and <a class="el" href="pdsc_family_pg.html#element_seq_block">seq_block</a> creates a configuration for debug access sequences.</li>
<li><a class="el" href="pdsc_family_pg.html#element_trace">trace</a> with the child elements <a class="el" href="pdsc_family_pg.html#element_trace_serialwire">trace_serialwire</a>, <a class="el" href="pdsc_family_pg.html#element_trace_traceport">trace_traceport</a>, and <a class="el" href="pdsc_family_pg.html#element_trace_tracebuffer">trace_tracebuffer</a> sets up the trace connection.</li>
</ul>
<h1><a class="anchor" id="pdsc_SequenceNameEnum_pg"></a>
Debug access sequences</h1>
<p>Debug access sequences define the activities of development tools to connect to a device using the debug channel for debugging, tracing, or flash programming. Several debug access sequences are predefined and executed in specific context. Refer to <a class="el" href="pdsc_family_pg.html#element_sequences">sequences</a> for details.</p>
<p>Software development tools should implement <a class="el" href="debug_description.html#default_sequences">Default debug access sequences</a>. These default sequences can be overwritten by device specific sequences using the <a class="el" href="pdsc_family_pg.html#element_sequence">sequence</a> element in the <a class="el" href="pdsc_family_pg.html#element_sequences">sequences</a> section of the PDSC file. Additionally, a PDSC file can contain user-defined sequences, for example to reuse access sequence fragments:</p>
<ul>
<li><a class="el" href="debug_description.html#usage_of_sequences">Usage of debug access sequences</a> explains how the sequences are used from a development tool point of view.</li>
<li><a class="el" href="debug_description.html#default_sequences">Default debug access sequences</a> lists all debug access sequences that are predefined by the CMSIS-Pack standard and shows the details of the default debug access sequences.</li>
<li><a class="el" href="debug_description.html#writing_sequences">Writing debug access sequences</a> explains how to write custom debug access sequences. These can be used to either override default sequences or to define device specific sequences.</li>
</ul>
<h1><a class="anchor" id="usage_of_sequences"></a>
Usage of debug access sequences</h1>
<p>Predefined Debug Access Sequences are used in the following context:</p>
<ul>
<li><b>Connect Debugger to Device</b> is executed when debugging or flash programming with the target starts.</li>
<li><b>Reset Device</b> is executed to reset the target.</li>
<li><b>Verify Code</b> is executed to verify the content after flash programming.</li>
<li><b>Disconnect Debugger</b> is executed when debugging or flash programming with the target stops.</li>
</ul>
<p>The following diagrams show how the Debug Access Sequences are executed by a development tool.</p>
<p><b>Connect Debugger to Device</b> is executed when debugging or flash programming with the target starts.</p>
<div class="image">
<img src="DebugConnect.png" alt="DebugConnect.png"/>
</div>
<p><b>Reset Device</b> is executed to reset the target.</p>
<div class="image">
<img src="Reset.png" alt="Reset.png"/>
</div>
<p><b>Verify Code</b> is executed to verify the content after flash programming.</p>
<div class="image">
<img src="CodeVerify.png" alt="CodeVerify.png"/>
</div>
<p><b>Disconnect Debugger</b> is executed when debugging or flash programming with the target stops.</p>
<div class="image">
<img src="DebugDisconnect.png" alt="DebugDisconnect.png"/>
</div>
<h1><a class="anchor" id="default_sequences"></a>
Default debug access sequences</h1>
<p>Debug access sequences get defined in the <a class="el" href="pdsc_family_pg.html#element_sequence">sequence</a> element. The following table lists the available predefined debug access sequences. <a class="el" href="debug_description.html#default_sequences">Default debug access sequences</a> are executed if they are not overwritten using a <a class="el" href="pdsc_family_pg.html#element_sequence">sequence</a> element. Refer to <a class="el" href="debug_description.html#usage_of_sequences">Usage of debug access sequences</a> for more information about the execution of these sequences.</p>
<p>For debug access sequences marked in <span class="XML-Token">ItalicRed</span>, no default sequence exists. The usage in a debug description requires a related <a class="el" href="pdsc_family_pg.html#element_sequence">sequence</a> element to be present. The other sequences should be implemented in a development tool. They are executed when no sequence definition exists in the PDSC file.</p>
<dl class="section note"><dt>Note</dt><dd>Default debug access sequences read the System Control Space (SCS) of the processor and assume that the SCS offset is implemented as defined in the Armv6-M/Armv7-M/Armv8-M architecture reference manual.</dd></dl>
<table  class="cmtable" summary="Enumeration: SequenceNameEnum">
<tr>
<th>name= </th><th>Description  </th></tr>
<tr>
<td class="XML-Token"><a class="el" href="debug_description.html#debugPortSetup">DebugPortSetup</a> </td><td>Prepare the target debug port for connection; is executed before acquiring access to the debug port.<br/>
 May include for example an SWJ-DP switch sequence as defined in the Arm Debug Interface (ADI) Architecture Specification.<br/>
 <b>This sequence must not contain debug port/access port register and target memory accesses other than:</b><ul>
<li><b>Reading the <em>DPIDR</em> debug port register to release an SWD connection from its line reset.</b></li>
<li><b>Writing the <em>TARGETSEL</em> debug port register (SWD protocol v2).</b>   </li>
</ul>
</td></tr>
<tr>
<td class="XML-Token"><a class="el" href="debug_description.html#debugPortStart">DebugPortStart</a> </td><td>Connect to the target debug port and power it up; is executed after DebugPortSetup.<br/>
 The parent <b>debugport</b> is default debug port for this sequence.<br/>
 <b>This sequence must not contain access port register and target memory accesses.</b>  </td></tr>
<tr>
<td class="XML-Token"><a class="el" href="debug_description.html#debugPortStop">DebugPortStop</a> </td><td>Power down and disconnect from target debug port.<br/>
 Executed as last step during target disconnect unless another debugger connection to this port is active. The parent <b>debugport</b> is default debug port for this sequence.<br/>
 <b>This sequence must not contain access port register and target memory accesses.</b>  </td></tr>
<tr>
<td class="XML-Token">DebugDeviceUnlock </td><td>Check if the device is in a locked state and unlock it. Use <b>query</b> command elements for user confirmation.<br/>
 Executed after having powered up the debug port.  </td></tr>
<tr>
<td class="XML-Token"><a class="el" href="debug_description.html#debugCoreStart">DebugCoreStart</a> </td><td>Initialize core debug system.<br/>
 Executed after having connected and powered up the default debug port for the connection.  </td></tr>
<tr>
<td class="XML-Token"><a class="el" href="debug_description.html#debugCoreStop">DebugCoreStop</a> </td><td>Uninitialized core debug system.<br/>
 Executed as last step during disconnect before powering down any debug ports no longer required for concurrent connections.  </td></tr>
<tr>
<td class="XML-Token">DebugCodeMemRemap </td><td>Remap memory to execution location.<br/>
 Executed before verifying memory content after flash programming. This is required to replicate a memory remap of a device bootloader (that is not executed during debug connection).   </td></tr>
<tr>
<td class="XML-Token"><a class="el" href="debug_description.html#resetSystem">ResetSystem</a> </td><td>Execute a system-wide reset via software mechanisms.   </td></tr>
<tr>
<td class="XML-Token"><a class="el" href="debug_description.html#resetProcessor">ResetProcessor</a> </td><td>Execute a processor reset via software mechanisms.   </td></tr>
<tr>
<td class="XML-Token"><a class="el" href="debug_description.html#resetHardware">ResetHardware</a> </td><td>Execute a system-wide reset via the dedicated debugger reset line, e.g. nRST.  </td></tr>
<tr>
<td class="XML-Token"><a class="el" href="debug_description.html#resetHardwareAssert">ResetHardwareAssert</a> </td><td>Assert a system-wide reset via the dedicated debugger reset line, e.g. nRST.   </td></tr>
<tr>
<td class="XML-Token"><a class="el" href="debug_description.html#resetHardwareDeassert">ResetHardwareDeassert</a> </td><td>De-assert a system-wide reset via the dedicated debugger reset line, e.g. nRST.   </td></tr>
<tr>
<td class="XML-Token"><a class="el" href="debug_description.html#resetCatchSet">ResetCatchSet</a> </td><td>Executed before a target reset to configure the vector catch to stop code execution after the reset.<br/>
 The implementation of <b>ResetCatchSet</b> requires an implementation of <b>ResetCatchClear</b> to free any hardware resources used for stopping the core.   </td></tr>
<tr>
<td class="XML-Token"><a class="el" href="debug_description.html#resetCatchClear">ResetCatchClear</a> </td><td>Executed after a target reset to free hardware resources allocated by <b>ResetCatchSet</b>.   </td></tr>
<tr>
<td class="XML-Token">FlashInit </td><td>Executed before starting a flash operation.   </td></tr>
<tr>
<td class="XML-Token">FlashUninit </td><td>Executed after a flash operation finished.   </td></tr>
<tr>
<td class="XML-Token">FlashEraseSector </td><td>Executed to erase a flash memory sector.   </td></tr>
<tr>
<td class="XML-Token">FlashEraseChip </td><td>Executed to erase all on-chip flash memory with target device specific erase technology. If this sequence is not implemented then a debugger can use <b>FlashEraseSector</b> to erase all flash memory.   </td></tr>
<tr>
<td class="XML-Token">FlashEraseDone </td><td>Executed after all flash memory erase operations are finished.   </td></tr>
<tr>
<td class="XML-Token">FlashProgramPage </td><td>Executed to program a single flash page.   </td></tr>
<tr>
<td class="XML-Token">FlashProgramDone </td><td>Executed after all flash programming operations are finished.   </td></tr>
<tr>
<td class="XML-Token">TraceStart </td><td>Enable target trace capture.<br/>
 Executed before the debugger powers up and configures standard CoreSight trace components, e.g. after the initial target connection as well as after a system-wide reset.   </td></tr>
<tr>
<td class="XML-Token">TraceStop </td><td>Disable target trace capture.<br/>
 Executed after the debugger disabled and powered down standard CoreSight trace components.   </td></tr>
<tr>
<td class="XML-Token">RecoverySupportStart </td><td>Executed before step or run command to support recovery from a lost target connection, e.g. after a low power mode.   </td></tr>
<tr>
<td class="XML-Token">RecoverySupportStop </td><td>Executed after step or run command in context of the <b>RecoverySupportStart</b> sequence.   </td></tr>
<tr>
<td class="XML-Token">RecoveryAcknowledge </td><td>Debugger acknowledge after recovering from a lost target connection. Can be executed independently from a <b>RecoverySupportStart</b> sequence.   </td></tr>
</table>
<h2>Predefined default debug access sequences </h2>
<p>The following sections the show the details of the predefined default debug access sequences.</p>
<h2><a class="anchor" id="debugPortSetup"></a>
DebugPortSetup</h2>
<p>Prepare the target debug port for connection.</p>
<div class="fragment"><div class="line">&lt;sequence name=<span class="stringliteral">&quot;DebugPortSetup&quot;</span>&gt;</div>
<div class="line">  &lt;block&gt;</div>
<div class="line">    __var isSWJ    = ((__protocol &amp;amp; 0x00010000) != 0);</div>
<div class="line">    __var protType = __protocol &amp;amp; 0x0000FFFF;</div>
<div class="line">  &lt;/block&gt;</div>
<div class="line"></div>
<div class="line">  &lt;!-- JTAG Protocol --&gt;</div>
<div class="line">  &lt;control <span class="keywordflow">if</span>=<span class="stringliteral">&quot;protType == 1&quot;</span>&gt;</div>
<div class="line">  </div>
<div class="line">    &lt;control <span class="keywordflow">if</span>=<span class="stringliteral">&quot;isSWJ&quot;</span>&gt;</div>
<div class="line">    </div>
<div class="line">      &lt;block atomic=<span class="stringliteral">&quot;1&quot;</span>&gt;</div>
<div class="line">        <span class="comment">// Ensure current debug interface is in reset state</span></div>
<div class="line">        DAP_SWJ_Sequence(51, 0x0007FFFFFFFFFFFF);</div>
<div class="line">        </div>
<div class="line">        <span class="comment">// Execute SWJ-DP Switch Sequence SWD to JTAG (0xE73C)</span></div>
<div class="line">        <span class="comment">// Change if SWJ-DP uses deprecated switch code (0xAEAE)</span></div>
<div class="line">        DAP_SWJ_Sequence(16, 0xE73C);</div>
<div class="line">        </div>
<div class="line">        <span class="comment">// Ensure JTAG interface is reset</span></div>
<div class="line">        DAP_SWJ_Sequence(6, 0x3F);</div>
<div class="line">      &lt;/block&gt;</div>
<div class="line">      </div>
<div class="line">    &lt;/control&gt;</div>
<div class="line">  </div>
<div class="line">    &lt;block atomic=<span class="stringliteral">&quot;1&quot;</span>&gt;</div>
<div class="line">      <span class="comment">// JTAG &quot;Soft&quot; Reset</span></div>
<div class="line">      DAP_JTAG_Sequence(6, 1, 0x3F);</div>
<div class="line">      DAP_JTAG_Sequence(1, 0, 0x01);</div>
<div class="line">    &lt;/block&gt;</div>
<div class="line"></div>
<div class="line">  &lt;/control&gt;</div>
<div class="line">  </div>
<div class="line">  &lt;!-- SWD Protocol --&gt;</div>
<div class="line">  &lt;control <span class="keywordflow">if</span>=<span class="stringliteral">&quot;protType == 2&quot;</span>&gt;</div>
<div class="line">  </div>
<div class="line">    &lt;control <span class="keywordflow">if</span>=<span class="stringliteral">&quot;isSWJ&quot;</span>&gt;</div>
<div class="line">      </div>
<div class="line">      &lt;block atomic=<span class="stringliteral">&quot;1&quot;</span>&gt;</div>
<div class="line">        <span class="comment">// Ensure current debug interface is in reset state</span></div>
<div class="line">        DAP_SWJ_Sequence(51, 0x0007FFFFFFFFFFFF);</div>
<div class="line">        </div>
<div class="line">        <span class="comment">// Execute SWJ-DP Switch Sequence JTAG to SWD (0xE79E)</span></div>
<div class="line">        <span class="comment">// Change if SWJ-DP uses deprecated switch code (0xEDB6)</span></div>
<div class="line">        DAP_SWJ_Sequence(16, 0xE79E);</div>
<div class="line">        </div>
<div class="line">        <span class="comment">// Enter SWD Line Reset State</span></div>
<div class="line">        DAP_SWJ_Sequence(51, 0x0007FFFFFFFFFFFF);  <span class="comment">// &amp;gt; 50 cycles SWDIO/TMS High</span></div>
<div class="line">        DAP_SWJ_Sequence(3,  0x00);                <span class="comment">// At least 2 idle cycles (SWDIO/TMS Low)</span></div>
<div class="line">      &lt;/block&gt;</div>
<div class="line">    </div>
<div class="line">    &lt;/control&gt;</div>
<div class="line">  </div>
<div class="line">    &lt;control <span class="keywordflow">if</span>=<span class="stringliteral">&quot;!isSWJ&quot;</span>&gt;</div>
<div class="line">    </div>
<div class="line">      &lt;block atomic=<span class="stringliteral">&quot;1&quot;</span>&gt;</div>
<div class="line">        <span class="comment">// Enter SWD Line Reset State</span></div>
<div class="line">        DAP_SWJ_Sequence(51, 0x0007FFFFFFFFFFFF);  <span class="comment">// &amp;gt; 50 cycles SWDIO/TMS High</span></div>
<div class="line">        DAP_SWJ_Sequence(3,  0x00);                <span class="comment">// At least 2 idle cycles (SWDIO/TMS Low)</span></div>
<div class="line">      &lt;/block&gt;</div>
<div class="line">      </div>
<div class="line">    &lt;/control&gt;</div>
<div class="line">    </div>
<div class="line">    &lt;block&gt;</div>
<div class="line">      <span class="comment">// Read DPIDR to enable SWD interface (SW-DPv1 and SW-DPv2)</span></div>
<div class="line">      ReadDP(0x0);</div>
<div class="line">    &lt;/block&gt;</div>
<div class="line"></div>
<div class="line">  &lt;/control&gt;</div>
<div class="line">  </div>
<div class="line">&lt;/sequence&gt;</div>
</div><!-- fragment --><h2><a class="anchor" id="debugPortStart"></a>
DebugPortStart</h2>
<p>Connect to the target debug port and power it up.</p>
<div class="fragment"><div class="line">&lt;sequence name=<span class="stringliteral">&quot;DebugPortStart&quot;</span>&gt;</div>
<div class="line">  </div>
<div class="line">  &lt;block&gt;</div>
<div class="line">    __var SW_DP_ABORT  = 0x0;</div>
<div class="line">    __var DP_CTRL_STAT = 0x4;</div>
<div class="line">    __var DP_SELECT    = 0x8;</div>
<div class="line">    __var powered_down = 0;</div>
<div class="line"></div>
<div class="line">    <span class="comment">// Switch to DP Register Bank 0</span></div>
<div class="line">    WriteDP(DP_SELECT, 0x00000000);</div>
<div class="line">  </div>
<div class="line">    <span class="comment">// Read DP CTRL/STAT Register and check if CSYSPWRUPACK and CDBGPWRUPACK bits are set</span></div>
<div class="line">    powered_down = ((ReadDP(DP_CTRL_STAT) &amp;amp; 0xA0000000) != 0xA0000000);</div>
<div class="line">  &lt;/block&gt;</div>
<div class="line">  </div>
<div class="line">  &lt;control <span class="keywordflow">if</span>=<span class="stringliteral">&quot;powered_down&quot;</span>&gt;</div>
<div class="line">  </div>
<div class="line">    &lt;block&gt;</div>
<div class="line">      <span class="comment">// Request Debug/System Power-Up</span></div>
<div class="line">      WriteDP(DP_CTRL_STAT, 0x50000000);</div>
<div class="line">    &lt;/block&gt;</div>
<div class="line">    </div>
<div class="line">    &lt;!-- Wait <span class="keywordflow">for</span> Power-Up Request to be acknowledged --&gt;</div>
<div class="line">    &lt;control <span class="keywordflow">while</span>=<span class="stringliteral">&quot;(ReadDP(DP_CTRL_STAT) &amp;amp; 0xA0000000) != 0xA0000000&quot;</span> timeout=<span class="stringliteral">&quot;1000000&quot;</span>/&gt;</div>
<div class="line">    </div>
<div class="line">    &lt;!-- JTAG Specific Part of sequence --&gt;</div>
<div class="line">    &lt;control <span class="keywordflow">if</span>=<span class="stringliteral">&quot;(__protocol &amp;amp; 0xFFFF) == 1&quot;</span>&gt;</div>
<div class="line">    </div>
<div class="line">      &lt;block&gt;</div>
<div class="line">        <span class="comment">// Init AP Transfer Mode, Transaction Counter, and Lane Mask (Normal Transfer Mode, Include all Byte Lanes)</span></div>
<div class="line">        <span class="comment">// Additionally clear STICKYORUN, STICKYCMP, and STICKYERR bits by writing &#39;1&#39;</span></div>
<div class="line">        WriteDP(DP_CTRL_STAT, 0x50000F32);</div>
<div class="line">      &lt;/block&gt;</div>
<div class="line">      </div>
<div class="line">    &lt;/control&gt;</div>
<div class="line">    </div>
<div class="line">    &lt;!-- SWD Specific Part of sequence --&gt;</div>
<div class="line">    &lt;control <span class="keywordflow">if</span>=<span class="stringliteral">&quot;(__protocol &amp;amp; 0xFFFF) == 2&quot;</span>&gt;</div>
<div class="line">    </div>
<div class="line">      &lt;block&gt;</div>
<div class="line">        <span class="comment">// Init AP Transfer Mode, Transaction Counter, and Lane Mask (Normal Transfer Mode, Include all Byte Lanes)</span></div>
<div class="line">        WriteDP(DP_CTRL_STAT, 0x50000F00);</div>
<div class="line">        </div>
<div class="line">        <span class="comment">// Clear WDATAERR, STICKYORUN, STICKYCMP, and STICKYERR bits of CTRL/STAT Register by write to ABORT register</span></div>
<div class="line">        WriteDP(SW_DP_ABORT, 0x0000001E);</div>
<div class="line">      &lt;/block&gt;</div>
<div class="line"></div>
<div class="line">    &lt;/control&gt;</div>
<div class="line">    </div>
<div class="line">  &lt;/control&gt;</div>
<div class="line">  </div>
<div class="line">&lt;/sequence&gt;</div>
</div><!-- fragment --><h2><a class="anchor" id="debugPortStop"></a>
DebugPortStop</h2>
<p>Power down and disconnect from target debug port.</p>
<div class="fragment"><div class="line">&lt;sequence name=<span class="stringliteral">&quot;DebugPortStop&quot;</span>&gt;</div>
<div class="line"></div>
<div class="line">  &lt;block&gt;</div>
<div class="line">    __var DP_CTRL_STAT = 0x4;</div>
<div class="line">    __var DP_SELECT    = 0x8;</div>
<div class="line">    </div>
<div class="line">    <span class="comment">// Switch to DP Register Bank 0</span></div>
<div class="line">    WriteDP(DP_SELECT, 0x00000000);</div>
<div class="line">    </div>
<div class="line">    <span class="comment">// Power Down Debug port</span></div>
<div class="line">    WriteDP(DP_CTRL_STAT, 0x00000000);</div>
<div class="line">  &lt;/block&gt;</div>
<div class="line"></div>
<div class="line">&lt;/sequence&gt;</div>
</div><!-- fragment --><h2><a class="anchor" id="debugCoreStart"></a>
DebugCoreStart</h2>
<p>Initialize core debug system.</p>
<div class="fragment"><div class="line">&lt;sequence name=<span class="stringliteral">&quot;DebugCoreStart&quot;</span>&gt;</div>
<div class="line"></div>
<div class="line">  &lt;block&gt;</div>
<div class="line">    <span class="comment">// System Control Space (SCS) offset as defined in Armv6-M/Armv7-M.</span></div>
<div class="line">  </div>
<div class="line">    __var SCS_Addr   = 0xE000E000;</div>
<div class="line">    __var DHCSR_Addr = SCS_Addr + 0xDF0;</div>
<div class="line"></div>
<div class="line">    <span class="comment">// Enable Core Debug via DHCSR</span></div>
<div class="line">    Write32(DHCSR_Addr, 0xA05F0001);</div>
<div class="line">  &lt;/block&gt;</div>
<div class="line">  </div>
<div class="line">&lt;/sequence&gt;</div>
</div><!-- fragment --><h2><a class="anchor" id="debugCoreStop"></a>
DebugCoreStop</h2>
<p>Un-initialize core debug system.</p>
<div class="fragment"><div class="line">&lt;sequence name=<span class="stringliteral">&quot;DebugCoreStop&quot;</span>&gt;</div>
<div class="line"></div>
<div class="line">  &lt;block&gt;</div>
<div class="line">    <span class="comment">// System Control Space (SCS) offset as defined in Armv6-M/Armv7-M.</span></div>
<div class="line">    </div>
<div class="line">    __var SCS_Addr   = 0xE000E000;</div>
<div class="line">    __var DHCSR_Addr = SCS_Addr + 0xDF0;</div>
<div class="line">    __var DEMCR_Addr = SCS_Addr + 0xDFC;</div>
<div class="line">    </div>
<div class="line">    <span class="comment">// Disable Core Debug via DHCSR</span></div>
<div class="line">    Write32(DHCSR_Addr, 0xA05F0000);</div>
<div class="line">    </div>
<div class="line">    <span class="comment">// Disable DWT and ITM blocks, DebugMonitor handler,</span></div>
<div class="line">    <span class="comment">// halting debug traps, and Reset Vector Catch.</span></div>
<div class="line">    Write32(DEMCR_Addr, 0x00000000);</div>
<div class="line">  &lt;/block&gt;</div>
<div class="line">  </div>
<div class="line">&lt;/sequence&gt;</div>
</div><!-- fragment --><h2><a class="anchor" id="resetSystem"></a>
ResetSystem</h2>
<p>Execute a system-wide reset via software mechanisms.</p>
<div class="fragment"><div class="line">&lt;sequence name=<span class="stringliteral">&quot;ResetSystem&quot;</span>&gt;</div>
<div class="line"></div>
<div class="line">  &lt;block&gt;</div>
<div class="line">    <span class="comment">// System Control Space (SCS) offset as defined in Armv6-M/Armv7-M.</span></div>
<div class="line"></div>
<div class="line">    __var SCS_Addr   = 0xE000E000;</div>
<div class="line">    __var AIRCR_Addr = SCS_Addr + 0xD0C;</div>
<div class="line">    __var DHCSR_Addr = SCS_Addr + 0xDF0;</div>
<div class="line">  </div>
<div class="line">    <span class="comment">// Execute SYSRESETREQ via AIRCR</span></div>
<div class="line">    Write32(AIRCR_Addr, 0x05FA0004);</div>
<div class="line">  &lt;/block&gt;</div>
<div class="line"></div>
<div class="line">  &lt;!-- Reset Recovery: Wait <span class="keywordflow">for</span> DHCSR.S_RESET_ST bit to clear on read --&gt;</div>
<div class="line">  &lt;control <span class="keywordflow">while</span>=<span class="stringliteral">&quot;(Read32(DHCSR_Addr) &amp;amp; 0x02000000)&quot;</span> timeout=<span class="stringliteral">&quot;500000&quot;</span>/&gt;</div>
<div class="line">  </div>
<div class="line">&lt;/sequence&gt;</div>
</div><!-- fragment --><h2><a class="anchor" id="resetProcessor"></a>
ResetProcessor</h2>
<p>Execute a processor reset via software mechanisms.</p>
<dl class="section note"><dt>Note</dt><dd>This Default Debug Access Sequence is empty for Armv6-M and Armv8-M based processors.</dd></dl>
<div class="fragment"><div class="line">&lt;sequence name=<span class="stringliteral">&quot;ResetProcessor&quot;</span>&gt;</div>
<div class="line"></div>
<div class="line">  &lt;block&gt;</div>
<div class="line">    <span class="comment">// System Control Space (SCS) offset as defined in Armv7-M.</span></div>
<div class="line"></div>
<div class="line">    __var SCS_Addr   = 0xE000E000;</div>
<div class="line">    __var AIRCR_Addr = SCS_Addr + 0xD0C;</div>
<div class="line">    __var DHCSR_Addr = SCS_Addr + 0xDF0;</div>
<div class="line">  </div>
<div class="line">    <span class="comment">// Execute VECTRESET via AIRCR</span></div>
<div class="line">    Write32(AIRCR_Addr, 0x05FA0001);</div>
<div class="line">  &lt;/block&gt;</div>
<div class="line">  </div>
<div class="line">  &lt;!-- Reset Recovery: Wait <span class="keywordflow">for</span> DHCSR.S_RESET_ST bit to clear on read --&gt;</div>
<div class="line">  &lt;control <span class="keywordflow">while</span>=<span class="stringliteral">&quot;(Read32(DHCSR_Addr) &amp;amp; 0x02000000)&quot;</span> timeout=<span class="stringliteral">&quot;500000&quot;</span>/&gt;</div>
<div class="line"></div>
<div class="line">&lt;/sequence&gt;</div>
</div><!-- fragment --><h2><a class="anchor" id="resetHardware"></a>
ResetHardware</h2>
<p>Execute a system-wide reset via the dedicated debugger reset line nRST.</p>
<div class="fragment"><div class="line">&lt;sequence name=<span class="stringliteral">&quot;ResetHardware&quot;</span>&gt;</div>
<div class="line">  </div>
<div class="line">  &lt;block&gt;</div>
<div class="line">    __var nReset      = 0x80;</div>
<div class="line">    __var canReadPins = 0;</div>
<div class="line">  </div>
<div class="line">    <span class="comment">// De-assert nRESET line</span></div>
<div class="line">    canReadPins = (DAP_SWJ_Pins(0x00, nReset, 0) != 0xFFFFFFFF);</div>
<div class="line">  &lt;/block&gt;</div>
<div class="line">  </div>
<div class="line">  &lt;!-- Keep reset active <span class="keywordflow">for</span> 50 ms --&gt;</div>
<div class="line">  &lt;control <span class="keywordflow">while</span>=<span class="stringliteral">&quot;1&quot;</span> timeout=<span class="stringliteral">&quot;50000&quot;</span>/&gt;</div>
<div class="line"></div>
<div class="line">  &lt;control <span class="keywordflow">if</span>=<span class="stringliteral">&quot;canReadPins&quot;</span>&gt;</div>
<div class="line">  </div>
<div class="line">    &lt;!-- Assert nRESET line and wait max. 1s <span class="keywordflow">for</span> recovery --&gt;</div>
<div class="line">    &lt;control <span class="keywordflow">while</span>=<span class="stringliteral">&quot;(DAP_SWJ_Pins(nReset, nReset, 0) &amp;amp; nReset) == 0&quot;</span> timeout=<span class="stringliteral">&quot;1000000&quot;</span>/&gt;</div>
<div class="line">    </div>
<div class="line">  &lt;/control&gt;</div>
<div class="line">  </div>
<div class="line">  &lt;control <span class="keywordflow">if</span>=<span class="stringliteral">&quot;!canReadPins&quot;</span>&gt;</div>
<div class="line">  </div>
<div class="line">    &lt;block&gt;</div>
<div class="line">      <span class="comment">// Assert nRESET line</span></div>
<div class="line">      DAP_SWJ_Pins(nReset, nReset, 0);</div>
<div class="line">    &lt;/block&gt;</div>
<div class="line">    </div>
<div class="line">    &lt;!-- Wait 100ms <span class="keywordflow">for</span> recovery <span class="keywordflow">if</span> nRESET not readable --&gt;</div>
<div class="line">    &lt;control <span class="keywordflow">while</span>=<span class="stringliteral">&quot;1&quot;</span> timeout=<span class="stringliteral">&quot;100000&quot;</span>/&gt;</div>
<div class="line">    </div>
<div class="line">  &lt;/control&gt;</div>
<div class="line">  </div>
<div class="line">&lt;/sequence&gt;</div>
</div><!-- fragment --><h2><a class="anchor" id="resetHardwareAssert"></a>
ResetHardwareAssert</h2>
<p>Assert a system-wide reset line nRST.</p>
<div class="fragment"><div class="line">&lt;sequence name=<span class="stringliteral">&quot;ResetHardwareAssert&quot;</span>&gt;</div>
<div class="line"></div>
<div class="line">  &lt;block&gt;</div>
<div class="line">      __var nReset = 0x80;</div>
<div class="line">    </div>
<div class="line">      <span class="comment">// De-assert nRESET line to activate the hardware reset</span></div>
<div class="line">      DAP_SWJ_Pins(0, nReset, 0);</div>
<div class="line">  &lt;/block&gt;</div>
<div class="line">  </div>
<div class="line">&lt;/sequence&gt;</div>
</div><!-- fragment --><h2><a class="anchor" id="resetHardwareDeassert"></a>
ResetHardwareDeassert</h2>
<p>De-Assert a system-wide reset line nRST.</p>
<div class="fragment"><div class="line">&lt;sequence name=<span class="stringliteral">&quot;ResetHardwareDeassert&quot;</span>&gt;</div>
<div class="line"></div>
<div class="line">  &lt;block&gt;</div>
<div class="line">    __var nReset      = 0x80;</div>
<div class="line">    __var canReadPins = 0;</div>
<div class="line">    </div>
<div class="line">    <span class="comment">// Assert nRESET line and check if nRESET is readable</span></div>
<div class="line">    canReadPins = (DAP_SWJ_Pins(nReset, nReset, 0) != 0xFFFFFFFF);</div>
<div class="line">  &lt;/block&gt;</div>
<div class="line"></div>
<div class="line">  &lt;!-- Wait max. 1s <span class="keywordflow">for</span> nRESET to recover from reset <span class="keywordflow">if</span> readable--&gt;</div>
<div class="line">  &lt;control <span class="keywordflow">if</span>=<span class="stringliteral">&quot;canReadPins&quot;</span> <span class="keywordflow">while</span>=<span class="stringliteral">&quot;(DAP_SWJ_Pins(nReset, nReset, 0) &amp;amp; nReset) == 0&quot;</span> timeout=<span class="stringliteral">&quot;1000000&quot;</span>/&gt;</div>
<div class="line">  </div>
<div class="line">  &lt;!-- Wait 100ms <span class="keywordflow">for</span> recovery <span class="keywordflow">if</span> nRESET not readable --&gt;</div>
<div class="line">  &lt;control <span class="keywordflow">if</span>=<span class="stringliteral">&quot;!canReadPins&quot;</span> <span class="keywordflow">while</span>=<span class="stringliteral">&quot;1&quot;</span> timeout=<span class="stringliteral">&quot;100000&quot;</span>/&gt;</div>
<div class="line"></div>
<div class="line">&lt;/sequence&gt;</div>
</div><!-- fragment --><h2><a class="anchor" id="resetCatchSet"></a>
ResetCatchSet</h2>
<p>Configure the target to stop code execution after a reset.</p>
<div class="fragment"><div class="line">&lt;sequence name=<span class="stringliteral">&quot;ResetCatchSet&quot;</span>&gt;</div>
<div class="line"></div>
<div class="line">  &lt;block&gt;</div>
<div class="line">    <span class="comment">// System Control Space (SCS) offset as defined</span></div>
<div class="line">    <span class="comment">// in Armv6-M/Armv7-M. Reimplement this sequence</span></div>
<div class="line">    <span class="comment">// if the SCS is located at a different offset.</span></div>
<div class="line"></div>
<div class="line">    __var SCS_Addr   = 0xE000E000;</div>
<div class="line">    __var DHCSR_Addr = SCS_Addr + 0xDF0;</div>
<div class="line">    __var DEMCR_Addr = SCS_Addr + 0xDFC;</div>
<div class="line">    __var value      = 0;</div>
<div class="line">  </div>
<div class="line">    <span class="comment">// Enable Reset Vector Catch in DEMCR</span></div>
<div class="line">    value = Read32(DEMCR_Addr);</div>
<div class="line">    Write32(DEMCR_Addr, (value | 0x00000001));</div>
<div class="line"></div>
<div class="line">    <span class="comment">// Read DHCSR to clear potentially set DHCSR.S_RESET_ST bit</span></div>
<div class="line">    Read32(DHCSR_Addr);</div>
<div class="line">  &lt;/block&gt;</div>
<div class="line"></div>
<div class="line">&lt;/sequence&gt;</div>
</div><!-- fragment --><h2><a class="anchor" id="resetCatchClear"></a>
ResetCatchClear</h2>
<p>Free hardware resources allocated by ResetCatchSet.</p>
<div class="fragment"><div class="line">&lt;sequence name=<span class="stringliteral">&quot;ResetCatchClear&quot;</span>&gt;</div>
<div class="line"></div>
<div class="line">  &lt;block&gt;</div>
<div class="line">    <span class="comment">// System Control Space (SCS) offset as defined</span></div>
<div class="line">    <span class="comment">// in Armv6-M/Armv7-M. Reimplement this sequence</span></div>
<div class="line">    <span class="comment">// if the SCS is located at a different offset.</span></div>
<div class="line">    </div>
<div class="line">    __var SCS_Addr   = 0xE000E000;</div>
<div class="line">    __var DEMCR_Addr = SCS_Addr + 0xDFC;</div>
<div class="line">    __var value      = 0;</div>
<div class="line">    </div>
<div class="line">    <span class="comment">// Disable Reset Vector Catch in DEMCR</span></div>
<div class="line">    value = Read32(DEMCR_Addr);</div>
<div class="line">    Write32(DEMCR_Addr, (value &amp;amp; (~0x00000001)));</div>
<div class="line">  &lt;/block&gt;</div>
<div class="line">  </div>
<div class="line">&lt;/sequence&gt;</div>
</div><!-- fragment --><h1><a class="anchor" id="nonstdExamples"></a>
Examples of non-standard debug access sequences</h1>
<h2><a class="anchor" id="traceStart"></a>
TraceStart</h2>
<div class="fragment"><div class="line">&lt;sequence name=<span class="stringliteral">&quot;TraceStart&quot;</span>&gt;</div>
<div class="line">  &lt;block&gt;</div>
<div class="line">    __var value      = 0;</div>
<div class="line">  </div>
<div class="line">    <span class="comment">//Enable SWO</span></div>
<div class="line">    value = Read8(0x40004D2A);</div>
<div class="line">    Write8(0x40004D2A, (value | 0x20));         <span class="comment">// Set the register</span></div>
<div class="line">    value = Read8(0x40004D2C);</div>
<div class="line">    Write8(0x40004D2C, (value &amp;amp; (~0x20)));  <span class="comment">// Clear the register</span></div>
<div class="line">  &lt;/block&gt;</div>
<div class="line">&lt;/sequence&gt;</div>
</div><!-- fragment --><h2><a class="anchor" id="debugDeviceUnlock"></a>
DebugDeviceUnlock</h2>
<div class="fragment"><div class="line">&lt;sequence name=<span class="stringliteral">&quot;DebugDeviceUnlock&quot;</span>&gt;</div>
<div class="line">  &lt;block&gt;</div>
<div class="line">    __var DAuthUserInput   = 0;</div>
<div class="line">    __var DAUTHSTATUS_Val  = 0;</div>
<div class="line">    __var DHCSR_Val        = 0;</div>
<div class="line">    __var SecureDebugEna   = 0;</div>
<div class="line">    __var SecureDebugAvail = 0;</div>
<div class="line">    __var DAuthVal         = 0;</div>
<div class="line">    __var Status           = 0;  <span class="comment">// AP Status value</span></div>
<div class="line"> </div>
<div class="line">    DAUTHSTATUS_Val  = Read32(0xE000EFB8);</div>
<div class="line">    DHCSR_Val        = Read32(0xE000EDF0);</div>
<div class="line">    DAP_Delay(100000);</div>
<div class="line">    SecureDebugAvail = (DAUTHSTATUS_Val &amp;amp; 0x00000020) ? 1 : 0;  <span class="comment">// SID: Secure Invasive Debug Implemented</span></div>
<div class="line">    Status = ReadAP(0x0);                                           <span class="comment">// Read Status register</span></div>
<div class="line">  &lt;/block&gt;</div>
<div class="line"> </div>
<div class="line">  &lt;control <span class="keywordflow">if</span>=<span class="stringliteral">&quot;SecureDebugAvail&quot;</span> info=<span class="stringliteral">&quot;Configure Debug Authentication if Security Extensions available&quot;</span>&gt;</div>
<div class="line">    &lt;block&gt;</div>
<div class="line">      SecureDebugEna = ((DHCSR_Val &amp;amp; 0x00100000) || ((DAUTHSTATUS_Val &amp;amp; 0x00000030) == 0x00000030)) ? 1 : 0;</div>
<div class="line">    &lt;/block&gt;</div>
<div class="line"> </div>
<div class="line">    &lt;control <span class="keywordflow">if</span>=<span class="stringliteral">&quot;DAuthFixed&quot;</span>&gt;</div>
<div class="line">      &lt;block&gt;</div>
<div class="line">        <span class="comment">// Debug Authentication as per Debug Configuration File</span></div>
<div class="line">        DAuthVal = DAuthConfig;</div>
<div class="line">      &lt;/block&gt;</div>
<div class="line">    &lt;/control&gt;</div>
<div class="line">    &lt;control <span class="keywordflow">if</span>=<span class="stringliteral">&quot;DAuthFixed == 0&quot;</span>&gt;</div>
<div class="line">      &lt;block&gt;</div>
<div class="line">        DAuthUserInput = Query(1, <span class="stringliteral">&quot;Enable Secure Debug?&quot;</span>, 3);</div>
<div class="line">      &lt;/block&gt;</div>
<div class="line">      &lt;control <span class="keywordflow">if</span>=<span class="stringliteral">&quot;DAuthUserInput == 3&quot;</span>&gt;</div>
<div class="line">        &lt;block&gt;</div>
<div class="line">          <span class="comment">// Enable Secure Debug</span></div>
<div class="line">          DAuthVal = 0xF;</div>
<div class="line">        &lt;/block&gt;</div>
<div class="line">      &lt;/control&gt;</div>
<div class="line">      &lt;control <span class="keywordflow">if</span>=<span class="stringliteral">&quot;DAuthUserInput != 3&quot;</span>&gt;</div>
<div class="line">        &lt;block&gt;</div>
<div class="line">          <span class="comment">// Disable Secure Debug</span></div>
<div class="line">          DAuthVal = 0x3;</div>
<div class="line">        &lt;/block&gt;</div>
<div class="line">      &lt;/control&gt;</div>
<div class="line">    &lt;/control&gt;</div>
<div class="line"> </div>
<div class="line">    &lt;control <span class="keywordflow">if</span>=<span class="stringliteral">&quot;SecureDebugEna&quot;</span>&gt;</div>
<div class="line">      &lt;block&gt;</div>
<div class="line">        <span class="comment">// Setup Secure Debug</span></div>
<div class="line">        Write32(0x50007000, DAuthVal);</div>
<div class="line">      &lt;/block&gt;</div>
<div class="line">    &lt;/control&gt;</div>
<div class="line">    &lt;control <span class="keywordflow">if</span>=<span class="stringliteral">&quot;SecureDebugEna == 0&quot;</span>&gt;</div>
<div class="line">      &lt;control <span class="keywordflow">if</span>=<span class="stringliteral">&quot;DAuthVal &amp;amp; 0x4&quot;</span>&gt;</div>
<div class="line">        &lt;block&gt;</div>
<div class="line">          Query(0, <span class="stringliteral">&quot;Cannot configure Debug Authentication, secure debug disabled! Please reboot FPGA!&quot;</span>, 1);</div>
<div class="line">        &lt;/block&gt;</div>
<div class="line">      &lt;/control&gt;</div>
<div class="line">    &lt;/control&gt;</div>
<div class="line">  &lt;/control&gt;</div>
<div class="line">&lt;/sequence&gt;</div>
</div><!-- fragment --><h2><a class="anchor" id="hwReset"></a>
User-defined hardware reset sequence</h2>
<div class="fragment"><div class="line">&lt;sequence name=<span class="stringliteral">&quot;HWReset&quot;</span>&gt;</div>
<div class="line">  &lt;block&gt;</div>
<div class="line">    __var protType = __protocol &amp;amp; 0x0000FFFF;</div>
<div class="line">  &lt;/block&gt;</div>
<div class="line"> </div>
<div class="line">  &lt;!-- JTAG variant--&gt;</div>
<div class="line">  &lt;control <span class="keywordflow">if</span>=<span class="stringliteral">&quot;protType == 1&quot;</span>&gt;</div>
<div class="line">    &lt;block atomic=<span class="stringliteral">&quot;true&quot;</span>&gt;</div>
<div class="line">      <span class="comment">// HW Reset Pulse</span></div>
<div class="line">      DAP_SWJ_Pins(0x00, 0x80, 0);</div>
<div class="line">      DAP_Delay(50000);</div>
<div class="line">      DAP_SWJ_Pins(0x80, 0x80, 0);</div>
<div class="line"> </div>
<div class="line">      <span class="comment">// Wait at least 200us</span></div>
<div class="line">      DAP_Delay(200);</div>
<div class="line"> </div>
<div class="line">      <span class="comment">// Register to SSW (Start-up Software) within 2ms</span></div>
<div class="line"> </div>
<div class="line">      <span class="comment">// JTAG Reset</span></div>
<div class="line">      DAP_JTAG_Sequence(6, 1, 0x7F);</div>
<div class="line">      DAP_JTAG_Sequence(1, 0, 0x01);</div>
<div class="line"> </div>
<div class="line">      <span class="comment">// Request Debug and System Power-Up</span></div>
<div class="line">      WriteDP(0x4, 0x50000F00);</div>
<div class="line"> </div>
<div class="line">      <span class="comment">// Init DP SELECT register</span></div>
<div class="line">      WriteDP(0x8, 0x00000000);</div>
<div class="line"> </div>
<div class="line">      <span class="comment">// Init AP CSW register</span></div>
<div class="line">      WriteAP(0x00, 0x23000052);</div>
<div class="line"> </div>
<div class="line">      <span class="comment">// Set TAR register to DHCSR address</span></div>
<div class="line">      WriteAP(0x4, 0xE000EDF0);</div>
<div class="line"> </div>
<div class="line">      <span class="comment">// Enable core debug (finishes tool register process)</span></div>
<div class="line">      WriteAP(0xC, 0xA05F0001);</div>
<div class="line"> </div>
<div class="line">      <span class="comment">// SSW will configure a HW BP0 at User Code start</span></div>
<div class="line">    &lt;/block&gt;</div>
<div class="line">  &lt;/control&gt;</div>
<div class="line">  </div>
<div class="line">  ...</div>
<div class="line">  </div>
<div class="line">&lt;/sequence&gt;</div>
</div><!-- fragment --><h2><a class="anchor" id="sequenceExample"></a>
Calling sequences in a control block</h2>
<div class="fragment"><div class="line">...</div>
<div class="line">&lt;control <span class="keywordflow">if</span>=<span class="stringliteral">&quot;siliconRevision &amp;gt;= 3&quot;</span> &gt;</div>
<div class="line">  &lt;block&gt;                                                 </div>
<div class="line">    Sequence(<span class="stringliteral">&quot;SecurityUnlock&quot;</span>);                           <span class="comment">// Execute TAP Sequence according to SiliconRevision</span></div>
<div class="line">    Sequence(<span class="stringliteral">&quot;Set_JTAG_CTL&quot;</span>);</div>
<div class="line">    Sequence(<span class="stringliteral">&quot;WaitIdleState&quot;</span>);</div>
<div class="line">    Sequence(<span class="stringliteral">&quot;SetIDCODES&quot;</span>);</div>
<div class="line">  &lt;/block&gt;</div>
<div class="line">&lt;/control&gt;</div>
<div class="line">...</div>
</div><!-- fragment --><h1><a class="anchor" id="writing_sequences"></a>
Writing debug access sequences</h1>
<p>To override a default sequence or to create a custom (default) sequence, you need to write <a class="el" href="pdsc_family_pg.html#element_sequence">sequence</a> elements. The following sections show how to use the built-in debug access syntax, expressions, and debug access functions to create custom sequences.</p>
<h2><a class="anchor" id="DebugSyntaxRules"></a>
Debug access syntax rules</h2>
<p>Debug accesses are described in <b>block</b> elements (within a debug access <b>sequence</b> or <b>control</b> element). The following syntax is used for this purpose:</p>
<ul>
<li>One or more statements have to be encapsulated in a <b>block</b> element.</li>
<li>Each statement must begin in a new line and is terminated by a <span class="XML-Token">;</span> character.</li>
<li>A typical statement consists of variable, followed by a <span class="XML-Token">=</span> character and an expression, where the <span class="XML-Token">=</span> character is an assignment of the <a class="el" href="debug_description.html#ExpressionType">expression</a> result to the variable: <div class="fragment"><div class="line">variable = expression;</div>
</div><!-- fragment --></li>
<li>Alternatively, a statement can be a sole <a class="el" href="debug_description.html#ExpressionType">expression</a> without storing its result to a variable. <div class="fragment"><div class="line">expression;</div>
</div><!-- fragment --></li>
<li>Comments begin with two slashes (<span class="XML-Token">//</span>) and end with a line break: <div class="fragment"><div class="line"><span class="comment">// Whole line is a comment</span></div>
<div class="line">variable = expression;  <span class="comment">// Comment appended to statement</span></div>
</div><!-- fragment --></li>
<li>Variables must be defined using the keyword <span class="XML-Token">__var</span>. The definition must include an initialization of the variable: <div class="fragment"><div class="line">__var variable = 0;</div>
</div><!-- fragment --></li>
<li>Variables can be defined only once within a scope. Scopes begin with entering a debug access sequence or a <b>control</b> element. They are extended to child <b>control</b> elements. Variables of a parent scope can be modified. Leaving a scope destroys all variables defined in it.<br/>
 <b><em>block</em> elements do not begin a new scope.</b> <div class="fragment"><div class="line">&lt;sequence name=<span class="stringliteral">&quot;MySequence&quot;</span>&gt;</div>
<div class="line">  </div>
<div class="line">  &lt;block info=<span class="stringliteral">&quot;Block 1&quot;</span>&gt;</div>
<div class="line">    __var condvar = 1;</div>
<div class="line">    __var myvar1  = 5;</div>
<div class="line">    __var myvar2  = 0;</div>
<div class="line">  &lt;/block&gt;</div>
<div class="line">  </div>
<div class="line">  &lt;control <span class="keywordflow">if</span>=<span class="stringliteral">&quot;condvar&quot;</span>&gt;</div>
<div class="line">    &lt;block&gt;</div>
<div class="line">      <span class="comment">// __var myvar1 = 2;      // Redefinition, not allowed!</span></div>
<div class="line">      __var myvar3 = 2;</div>
<div class="line">      myvar2 = myvar1 + myvar3; <span class="comment">// Assign value (5+2) = 7</span></div>
<div class="line">    &lt;/block&gt;</div>
<div class="line">  &lt;/control&gt;</div>
<div class="line">  </div>
<div class="line">  &lt;block info=<span class="stringliteral">&quot;Block 2&quot;</span>&gt;</div>
<div class="line">    myvar1 = myvar2 + 1;  <span class="comment">// Variable myvar1 holds the value &#39;8&#39; after this statement</span></div>
<div class="line">    <span class="comment">// myvar2 = myvar3;   // myvar3 does not exist in this scope, not allowed!</span></div>
<div class="line">  &lt;/block&gt;</div>
<div class="line">  </div>
<div class="line">&lt;/sequence&gt;</div>
</div><!-- fragment --></li>
<li>The debug access variables <b>__dp</b>, <b>__ap</b>, and <b>__errorcontrol</b> can be modified within a debug access sequence. An assigned value is held until leaving the sequence. Calling another sequence by the <b>Sequence</b> debug access function will push their values on a sequence execution stack. The values are restored when returning from such a call.</li>
<li>The debug access variable <b>__Result</b> can be modified within a debug access sequence. Its value is held until the debug access sequence returns to the debugger. Hence its value is <b>not</b> pushed on a sequence execution stack when calling into another sequence by the <b>Sequence</b> debug access function.</li>
</ul>
<h2><a class="anchor" id="ExpressionType"></a>
Expression rules</h2>
<p>Expressions are used in various places to describe one of the following:</p>
<ul>
<li>A value as assigned in a <a class="el" href="debug_description.html#DebugSyntaxRules">debug access statement</a>.</li>
<li>A condition to use in the <b>if</b> attribute of a <b>control</b> element.</li>
<li>A condition to use in the <b>while</b> attribute of a <b>control</b> element.</li>
<li>A parameter to a debug access function as described below.</li>
</ul>
<p>An expression may consist of the following:</p>
<ul>
<li>Constant numbers in decimal and hexadecimal representation (prefix <span class="XML-Token">0x</span>).</li>
<li>Arithmetic operators such as <span class="XML-Token">+</span>, <span class="XML-Token">-</span>, <span class="XML-Token">*</span>, <span class="XML-Token">/</span>, and <span class="XML-Token">%</span>.</li>
<li>Bit-arithmetic operators such as <span class="XML-Token">&amp;</span>, <span class="XML-Token">|</span>, <span class="XML-Token">~</span>, <span class="XML-Token">^</span>, <span class="XML-Token">&gt;&gt;</span>, and <span class="XML-Token">&lt;&lt;</span>.</li>
<li>Comparison-operators such as <span class="XML-Token">==</span>, <span class="XML-Token">!=</span>, <span class="XML-Token">&lt;</span>, <span class="XML-Token">&gt;</span>, <span class="XML-Token">&lt;=</span>, and <span class="XML-Token">&gt;=</span>.</li>
<li>Logic operators such as <span class="XML-Token">!</span>, <span class="XML-Token">&amp;&amp;</span>, <span class="XML-Token">||</span>, and <span class="XML-Token">==</span>.</li>
<li>Conditional expression operations like:<div class="fragment"><div class="line">(x &lt; y) ? a : b </div>
</div><!-- fragment --></li>
<li>Precedence of sub-expressions is indicated by brackets (<span class="XML-Token">(</span>, <span class="XML-Token">)</span>). C-like precedence applies if brackets are omitted.</li>
<li>References to <a class="el" href="debug_description.html#DebugVars">debug access variables</a> for evaluating debug settings.</li>
<li>Calls to <a class="el" href="debug_description.html#DebugFunctions">debug access functions</a>.</li>
</ul>
<dl class="section note"><dt>Note</dt><dd><ul>
<li>All values used in expressions resolve to 64-bit unsigned integer values.</li>
<li>All logic-operations and comparisons resolve to the value <span class="XML-Token">1</span> if true, to <span class="XML-Token">0</span> otherwise.</li>
<li>XML prohibits the use of the characters <span class="XML-Token">&amp;</span>, <span class="XML-Token">&lt;</span>, and <span class="XML-Token">&gt;</span>. Use the corresponding XML entity names instead: <span class="XML-Token">&amp;amp;</span>, <span class="XML-Token">&amp;lt;</span>, and <span class="XML-Token">&amp;gt;</span>.</li>
</ul>
</dd></dl>
<p>&#160;</p>
<h2><a class="anchor" id="DebugFunctions"></a>
Debug access functions</h2>
<p>Debug access functions can be called in expressions in order to interact with the target device and the user. Parameters to functions can again be expressions.<br/>
 By default, a debugger must abort the execution of a debug access sequence if a function call fails. However, this behavior can be controlled from a sequence by the <b>__errorcontrol</b> <a class="el" href="debug_description.html#DebugVars">debug access variable</a>.<br/>
 <br/>
 The following table describes the existing debug access functions, their parameters and the debug access variables which are evaluated for the function call.</p>
<table  class="cmtable" summary="ExpressionType: debug access functions">
<tr>
<th>Function </th><th>Description  </th></tr>
<tr>
<td style="white-space: nowrap"><pre>Sequence("name")</pre> </td><td><p class="starttd">Execute a debug access sequence. Calling a sequence by this function causes the modifiable debug access variables <b>__dp</b>, <b>__ap</b>, and <b>__errorcontrol</b> to be pushed on a sequence execution stack. Returning from such a call will restore the state of these variables.<br/>
 <br/>
 <b>Parameters:</b><br/>
</p>
<ul>
<li>name: Name of the sequence to execute. It must be enclosed by quotes.</li>
</ul>
<p><b>Return Value:</b><br/>
 Always returns <span class="XML-Token">0</span>.</p>
<p class="endtd"><b>Code Example:</b><br/>
 Refer to <a class="el" href="debug_description.html#sequenceExample">Calling sequences in a control block</a>   </p>
</td></tr>
<tr>
<td style="white-space: nowrap"><pre>Read8(addr)</pre> </td><td><p class="starttd">Read an 8-bit value from target memory. <b>A device must support native 8-bit memory accesses for this function to succeed.</b><br/>
 <br/>
 <b>Parameters:</b><br/>
</p>
<ul>
<li>addr: Memory address to read from.</li>
</ul>
<p><b>Debug Access Variables:</b><br/>
</p>
<ul>
<li>__dp: The debug port to use for this memory access.</li>
<li>__ap: The access port to use for this memory access.</li>
</ul>
<p><b>Return Value:</b><br/>
 The 8-bit value as read from target memory.</p>
<p class="endtd"><b>Code Example:</b><br/>
 Refer to <a class="el" href="debug_description.html#traceStart">TraceStart</a>   </p>
</td></tr>
<tr>
<td style="white-space: nowrap"><pre>Read16(addr)</pre> </td><td><p class="starttd">Read an 16-bit value from target memory. <b>A device must support native 16-bit memory accesses for this function to succeed.</b><br/>
 <br/>
 <b>Parameters:</b><br/>
</p>
<ul>
<li>addr: Memory address to read from.</li>
</ul>
<p><b>Debug Access Variables:</b><br/>
</p>
<ul>
<li>__dp: The debug port to use for this memory access.</li>
<li>__ap: The access port to use for this memory access.</li>
</ul>
<p class="endtd"><b>Return Value:</b><br/>
 The 16-bit value as read from target memory.   </p>
</td></tr>
<tr>
<td style="white-space: nowrap"><pre>Read32(addr)</pre> </td><td><p class="starttd">Read an 32-bit value from target memory. <b>A device must support native 32-bit memory accesses for this function to succeed.</b><br/>
 <br/>
 <b>Parameters:</b><br/>
</p>
<ul>
<li>addr: Memory address to read from.</li>
</ul>
<p><b>Debug Access Variables:</b><br/>
</p>
<ul>
<li>__dp: The debug port to use for this memory access.</li>
<li>__ap: The access port to use for this memory access.</li>
</ul>
<p><b>Return Value:</b><br/>
 The 32-bit value as read from target memory.</p>
<p class="endtd"><b>Code Example:</b><br/>
 Refer to <a class="el" href="debug_description.html#resetSystem">ResetSystem</a>   </p>
</td></tr>
<tr>
<td style="white-space: nowrap"><pre>Read64(addr)</pre> </td><td><p class="starttd">Read an 64-bit value from target memory. <b>A device must support native 64-bit memory accesses for this function to succeed.</b><br/>
 <br/>
 <b>Parameters:</b><br/>
</p>
<ul>
<li>addr: Memory address to read from.</li>
</ul>
<p><b>Debug Access Variables:</b><br/>
</p>
<ul>
<li>__dp: The debug port to use for this memory access.</li>
<li>__ap: The access port to use for this memory access.</li>
</ul>
<p class="endtd"><b>Return Value:</b><br/>
 The 64-bit value as read from target memory.   </p>
</td></tr>
<tr>
<td style="white-space: nowrap"><pre>ReadAP(addr)</pre> </td><td><p class="starttd">Read a 32-bit value from an access port register.<br/>
 <br/>
 <b>Parameters:</b><br/>
</p>
<ul>
<li>addr: AP register address to read from. Addresses larger than <span class="XML-Token">0xF</span> automatically cause an AP register bank switch.</li>
</ul>
<p><b>Debug Access Variables:</b><br/>
</p>
<ul>
<li>__dp: The debug port to use for this memory access.</li>
<li>__ap: The access port to use for this memory access.</li>
</ul>
<p><b>Return Value:</b><br/>
 The 32-bit value as read from the AP register.</p>
<p class="endtd"><b>Code Example:</b><br/>
 Refer to <a class="el" href="debug_description.html#debugDeviceUnlock">DebugDeviceUnlock</a>   </p>
</td></tr>
<tr>
<td style="white-space: nowrap"><pre>ReadDP(addr)</pre> </td><td><p class="starttd">Read a 32-bit value from a debug port register.<br/>
 <br/>
 <b>Parameters:</b><br/>
</p>
<ul>
<li>addr: DP register address to read from.</li>
</ul>
<p><b>Debug Access Variables:</b><br/>
</p>
<ul>
<li>__dp: The debug port to use for this memory access.</li>
</ul>
<p><b>Return Value:</b><br/>
 The 32-bit value as read from the DP register.</p>
<p class="endtd"><b>Code Example:</b><br/>
 Refer to <a class="el" href="debug_description.html#debugPortSetup">DebugPortSetup</a>   </p>
</td></tr>
<tr>
<td style="white-space: nowrap"><pre>Write8(addr, val)</pre> </td><td><p class="starttd">Write an 8-bit value to target memory. <b>A device must support native 8-bit memory accesses for this function to succeed.</b><br/>
 <br/>
 <b>Parameters:</b><br/>
</p>
<ul>
<li>addr: Memory address to write to.</li>
<li>val: Value to write.</li>
</ul>
<p><b>Debug Access Variables:</b><br/>
</p>
<ul>
<li>__dp: The debug port to use for this memory access.</li>
<li>__ap: The access port to use for this memory access.</li>
</ul>
<p><b>Return Value:</b><br/>
 Always returns <span class="XML-Token">0</span>.</p>
<p class="endtd"><b>Code Example:</b><br/>
 Refer to <a class="el" href="debug_description.html#traceStart">TraceStart</a>   </p>
</td></tr>
<tr>
<td style="white-space: nowrap"><pre>Write16(addr, val)</pre> </td><td><p class="starttd">Write a 16-bit value to target memory. <b>A device must support native 16-bit memory accesses for this function to succeed.</b><br/>
 <br/>
 <b>Parameters:</b><br/>
</p>
<ul>
<li>addr: Memory address to write to.</li>
<li>val: Value to write.</li>
</ul>
<p><b>Debug Access Variables:</b><br/>
</p>
<ul>
<li>__dp: The debug port to use for this memory access.</li>
<li>__ap: The access port to use for this memory access.</li>
</ul>
<p class="endtd"><b>Return Value:</b><br/>
 Always returns <span class="XML-Token">0</span>.   </p>
</td></tr>
<tr>
<td style="white-space: nowrap"><pre>Write32(addr, val)</pre> </td><td><p class="starttd">Write a 32-bit value to target memory. <b>A device must support native 32-bit memory accesses for this function to succeed.</b><br/>
 <br/>
 <b>Parameters:</b><br/>
</p>
<ul>
<li>addr: Memory address to write to.</li>
<li>val: Value to write.</li>
</ul>
<p><b>Debug Access Variables:</b><br/>
</p>
<ul>
<li>__dp: The debug port to use for this memory access.</li>
<li>__ap: The access port to use for this memory access.</li>
</ul>
<p><b>Return Value:</b><br/>
 Always returns <span class="XML-Token">0</span>.</p>
<p class="endtd"><b>Code Example:</b><br/>
 Refer to <a class="el" href="debug_description.html#debugCoreStart">DebugCoreStart</a>   </p>
</td></tr>
<tr>
<td style="white-space: nowrap"><pre>Write64(addr, val)</pre> </td><td><p class="starttd">Write a 64-bit value to target memory. <b>A device must support native 64-bit memory accesses for this function to succeed.</b><br/>
 <br/>
 <b>Parameters:</b><br/>
</p>
<ul>
<li>addr: Memory address to write to.</li>
<li>val: Value to write.</li>
</ul>
<p><b>Debug Access Variables:</b><br/>
</p>
<ul>
<li>__dp: The debug port to use for this memory access.</li>
<li>__ap: The access port to use for this memory access.</li>
</ul>
<p class="endtd"><b>Return Value:</b><br/>
 Always returns <span class="XML-Token">0</span>.   </p>
</td></tr>
<tr>
<td style="white-space: nowrap"><pre>WriteAP(addr, val)</pre> </td><td><p class="starttd">Write a 32-bit value to an access port register. Addresses larger than 0xF automatically cause an AP register bank switch.<br/>
 <br/>
 <b>Parameters:</b><br/>
</p>
<ul>
<li>addr: Memory address to write to.</li>
<li>val: Value to write.</li>
</ul>
<p><b>Debug Access Variables:</b><br/>
</p>
<ul>
<li>__dp: The debug port to use for this memory access.</li>
<li>__ap: The access port to use for this memory access.</li>
</ul>
<p><b>Return Value:</b><br/>
 Always returns <span class="XML-Token">0</span>.</p>
<p class="endtd"><b>Code Example:</b><br/>
 Refer to <a class="el" href="debug_description.html#hwReset">User-defined hardware reset sequence</a>   </p>
</td></tr>
<tr>
<td style="white-space: nowrap"><pre>WriteDP(addr, val)</pre> </td><td><p class="starttd">Write a 32-bit value to a debug port register.<br/>
 <br/>
 <b>Parameters:</b><br/>
</p>
<ul>
<li>addr: Memory address to write to.</li>
<li>val: Value to write.</li>
</ul>
<p><b>Debug Access Variables:</b><br/>
</p>
<ul>
<li>__dp: The debug port to use for this memory access.</li>
</ul>
<p><b>Return Value:</b><br/>
 Always returns <span class="XML-Token">0</span>.</p>
<p class="endtd"><b>Code Example:</b><br/>
 Refer to <a class="el" href="debug_description.html#debugPortStart">DebugPortStart</a>   </p>
</td></tr>
<tr>
<td style="white-space: nowrap"><pre>FlashBufferWrite(addr, offs, len, mode)</pre> </td><td><p class="starttd">Write flash buffer contents into target memory. A debugger fills the flash buffer before it executes a flash programming sequence.<br/>
 <br/>
 <b>Parameters:</b><br/>
</p>
<ul>
<li>addr: Target memory buffer or register interface address to write the flash buffer contents. Must be a multiple of the number of bytes as specified by access size in parameter <b>mode</b>.</li>
<li>offs: Offset into the flash buffer to start writing from. Must be a multiple of the number of bytes as specified by access size in parameter <b>mode</b>.</li>
<li>len : Number of bytes to write to the target. If <b>offs</b> + <b>len</b> exceeds the flash buffer length set in variable <b>__FlashLen</b>, then the remaining bytes are filled with the pattern as specified by attribute <b>filler</b> of the <a class="el" href="pdsc_family_pg.html#element_flashblock">block</a> element. Must be a multiple of the number of bytes as specified by access size in parameter <b>mode</b>.</li>
<li>mode: Target access mode. The following bit map applies:<ul>
<li>Bit 0..8: Debug access size. One of <span class="XML-Token">8</span>, <span class="XML-Token">16</span>, <span class="XML-Token">32</span> and <span class="XML-Token">64</span>. The specified debug access size must be supported by the target debug access port.</li>
<li>Bit 0: Additionally, set this Bit to <span class="XML-Token">1</span> to increment the target address after each debug write access of the specified size.</li>
<li>Bit 9..63: Reserved</li>
</ul>
</li>
</ul>
<p><b>Debug Access Variables:</b><br/>
</p>
<ul>
<li>__dp: The debug port to use for this memory access.</li>
<li>__ap: The access port to use for this memory access.</li>
</ul>
<p class="endtd"><b>Return Value:</b><br/>
 Always returns <span class="XML-Token">0</span>.   </p>
</td></tr>
<tr>
<td style="white-space: nowrap"><pre>DAP_Delay(delay)</pre> </td><td><p class="starttd">Debug probe command to wait for a specific delay.<br/>
 <br/>
 <b>Parameters:</b><br/>
</p>
<ul>
<li>delay: Wait time in microseconds.</li>
</ul>
<p><b>Return Value:</b><br/>
 Always returns <span class="XML-Token">0</span>.</p>
<p class="endtd"><b>Code Example:</b><br/>
 Refer to <a class="el" href="debug_description.html#debugDeviceUnlock">DebugDeviceUnlock</a>   </p>
</td></tr>
<tr>
<td style="white-space: nowrap"><pre>DAP_WriteABORT(value)</pre> </td><td><p class="starttd">Debug probe command to write an abort request to the CoreSight ABORT register of the target debug port.<br/>
 <br/>
 <b>Parameters:</b><br/>
</p>
<ul>
<li>value: 32-bit value to write into the CoreSight ABORT register.</li>
</ul>
<p><b>Debug Access Variables:</b><br/>
</p>
<ul>
<li>__dp: The debug port to use for this memory access.</li>
</ul>
<p class="endtd"><b>Return Value:</b><br/>
 Always returns <span class="XML-Token">0</span>.   </p>
</td></tr>
<tr>
<td style="white-space: nowrap"><pre>DAP_SWJ_Pins(pinout, pinselect, pinwait)</pre> </td><td><p class="starttd">Debug probe command to monitor and control the I/O Pins including the nRESET device reset line.<br/>
 <b>I/O Pin Mapping</b> for <b>pinout</b>, <b>pinselect</b>, and <b>pinwait</b>:</p>
<ul>
<li>Bit 0: SWCLK/TCK</li>
<li>Bit 1: SWDIO/TMS</li>
<li>Bit 2: TDI</li>
<li>Bit 3: TDO</li>
<li>Bit 5: nTRST</li>
<li>Bit 7: nRESET</li>
</ul>
<p><br/>
 The <b>pinwait</b> time is useful in systems where the nRESET pin is implemented as open-drain output. After nRESET is de-asserted by the debugger, external circuit may still hold the target Device under reset for a time. Using the <b>pinwait</b> time, the debugger may monitor selected I/O Pins and wait until they the expected value appears or a timeout expires.<br/>
 <br/>
 <b>Parameters:</b><br/>
</p>
<ul>
<li>pinout: Value for selected output pins.</li>
<li>pinselect: Selects which output pins will be modified.</li>
<li>pinwait: Wait timeout for the selected output to stabilize. A debugger must extend this timeout to the closest possible time granularity.<ul>
<li>0 = no wait</li>
<li>1 .. 3000000 = time in microseconds (max 3s)</li>
</ul>
</li>
</ul>
<p class="endtd"><b>Return Value:</b><br/>
 The state of the I/O Pins at the end of this operation. If a debugger is not capable of monitoring the I/O Pins, it must return a value of <span class="XML-Token">0xFFFFFFFF</span>.   </p>
</td></tr>
<tr>
<td style="white-space: nowrap"><pre>DAP_SWJ_Clock(val)</pre> </td><td><p class="starttd">Debug probe command to set the clock frequency for JTAG and SWD communication mode.<br/>
 <br/>
 <b>Parameters:</b><br/>
</p>
<ul>
<li>val: Maximum SWD/JTAG Clock (SWCLK/TCK) value in Hz.</li>
</ul>
<p><b>Return Value:</b><br/>
 Always returns <span class="XML-Token">0</span>.</p>
<p class="endtd"><b>Code Example:</b><br/>
 Refer to <a class="el" href="debug_description.html#resetHardware">ResetHardware</a>   </p>
</td></tr>
<tr>
<td style="white-space: nowrap"><pre>DAP_SWJ_Sequence(cnt, val)</pre> </td><td><p class="starttd">Debug probe command to generate required SWJ sequences, e.g. for SWD/JTAG Reset, SWD&lt;-&gt;JTAG switch and Dormant operation.<br/>
 <br/>
 <b>Parameters:</b><br/>
</p>
<ul>
<li>cnt: Number of bits in sequence: 1..64. Larger sequences need to be implemented by multiple subsequent <b>DAP_SWJ_Sequence</b> calls. Such a sequence of <b>DAP_SWJ_Sequence</b> commands must be encapsulated in an atomic <b>block</b> to ensure correct execution.</li>
<li>val: Sequence generated on SWDIO/TMS (with clock @SWCLK/TCK), LSB transmitted first.</li>
</ul>
<p><b>Return Value:</b><br/>
 Always returns <span class="XML-Token">0</span>.</p>
<p class="endtd"><b>Code Example:</b><br/>
 Refer to <a class="el" href="debug_description.html#debugPortSetup">DebugPortSetup</a>   </p>
</td></tr>
<tr>
<td style="white-space: nowrap"><pre>DAP_JTAG_Sequence(cnt, tms, tdi)</pre> </td><td><p class="starttd">Debug probe command to generate a JTAG sequence with fixed TMS value and capture TDO.<br/>
 <br/>
 <b>Parameters:</b><br/>
</p>
<ul>
<li>cnt: Length of the JTAG sequence (number of TCK cycles and TDI bits): 1..64</li>
<li>tms: Fixed TMS value: 0..1</li>
<li>tdi: Data generated on TDI with one bit per TCK cycle, LSB transmitted first.</li>
</ul>
<p class="endtd"><b>Return Value:</b><br/>
 Data captured from TDO with one bit per TCK cycle, LSB captured first and padded with <span class="XML-Token">0</span>s.   </p>
</td></tr>
<tr>
<td style="white-space: nowrap"><pre>Query(type, "message", default)</pre> </td><td><p class="starttd">Query user input. The sequence execution stalls depending on the used <b>type</b>. If the debugger runs in a batch mode, this function returns the value <b>default</b>.<br/>
 <br/>
 <b>Parameters:</b><br/>
</p>
<ul>
<li>type: Query type. Can be one of:<ul>
<li><span class="XML-Token">0</span> : <b>Query_Ok</b>, displays an informative message which has to be confirmed by the user. This type allows the result <b>OK</b>.</li>
<li><span class="XML-Token">1</span> : <b>Query_YesNo</b>, displays a query with the allowed results <b>Yes</b> and <b>No</b>.</li>
<li><span class="XML-Token">2</span> : <b>Query_YesNoCancel</b>, displays a query with the allowed results <b>Yes</b>, <b>No</b>, and <b>Cancel</b>.</li>
<li><span class="XML-Token">3</span> : <b>Query_OkCancel</b>, displays a query with the allowed results <b>OK</b> and <b>Cancel</b>.</li>
</ul>
</li>
<li>message: A constant string with the query message to display. It must not be an expression and it must be enclosed by quotes.</li>
<li>default: The default value to return if the debugger runs in batch mode. See <b>Return Values</b> for a list of allowed values.</li>
</ul>
<p><b>Return Value:</b><br/>
 The result of the query. The user input maps to the following numbers:</p>
<ul>
<li>Error : <span class="XML-Token">0</span></li>
<li>OK : <span class="XML-Token">1</span></li>
<li>Cancel : <span class="XML-Token">2</span></li>
<li>Yes : <span class="XML-Token">3</span></li>
<li>No : <span class="XML-Token">4</span></li>
</ul>
<p class="endtd"><b>Code Example:</b><br/>
 Refer to <a class="el" href="debug_description.html#debugPortSetup">DebugPortSetup</a>   </p>
</td></tr>
<tr>
<td style="white-space: nowrap"><pre>QueryValue("message", default)</pre> </td><td><p class="starttd">Query input value from user. The sequence execution stalls until the user has entered a value or canceled the query. This function returns the <b>default</b> value if the user canceled the query or if the debugger runs in a batch mode.<br/>
 <br/>
 <b>Parameters:</b><br/>
</p>
<ul>
<li>message: A constant string with the query message to display. It must not be an expression and it must be enclosed by quotes.</li>
<li>default: The default value to return if the user cancels the query or if the debugger runs in batch mode.</li>
</ul>
<p><b>Return Value:</b><br/>
 The queried value.</p>
<p class="endtd"></p>
</td></tr>
<tr>
<td style="white-space: nowrap"><pre>Message(type, "format", ...)</pre> </td><td><p class="starttd">Outputs a message to a log window.<br/>
 <br/>
 <b>Parameters:</b><br/>
</p>
<ul>
<li>type: Message type. Can be one of:<ul>
<li><span class="XML-Token">0</span> : <b>Info</b>, outputs an informative message.</li>
<li><span class="XML-Token">1</span> : <b>Warning</b>, outputs a warning.</li>
<li><span class="XML-Token">2</span> : <b>Error</b>, outputs an error. Sequence execution aborts.</li>
</ul>
</li>
<li>format: A constant string with the message format. It must not be an expression and it must be enclosed by quotes. The string has the following format:<br/>
 <div class="fragment"><div class="line">%[flags][width][.precision]specifier</div>
</div><!-- fragment --><ul>
<li>Specifiers:<ul>
<li><span class="XML-Token">%u</span>: 32-bit unsigned decimal integer.</li>
<li><span class="XML-Token">%llu</span>: 64-bit unsigned decimal integer.</li>
<li><span class="XML-Token">%x</span>: 32-bit unsigned hexadecimal integer, lower case letters.</li>
<li><span class="XML-Token">%llx</span>: 64-bit unsigned hexadecimal integer, lower case letters.</li>
<li><span class="XML-Token">%X</span>: 32-bit unsigned hexadecimal integer, upper case letters.</li>
<li><span class="XML-Token">%llX</span>: 64-bit unsigned hexadecimal integer, upper case letters.</li>
<li><span class="XML-Token">%o</span>: 32-bit unsigned octal integer.</li>
<li><span class="XML-Token">%llo</span>: 64-bit unsigned octal integer.</li>
<li><span class="XML-Token">%b</span>: 32-bit unsigned binary integer.</li>
<li><span class="XML-Token">%llb</span>: 64-bit unsigned binary integer.</li>
<li><span class="XML-Token">%f</span>: Single-precision (32-bit) floating point value.</li>
<li><span class="XML-Token">%Lf</span>: Double-precision (64-bit) floating point value.</li>
<li><span class="XML-Token">%s</span>: Constant character string. Must not be an expression.</li>
<li><span class="XML-Token">%%</span>: Print <span class="XML-Token">%</span> character.</li>
</ul>
</li>
<li>Flags:<ul>
<li><span class="XML-Token">0</span>: Pad the displayed value with zeros instead of spaces if padding is required by the <span class="XML-Token">width</span> option.</li>
</ul>
</li>
<li>Width: Minimum number of displayed characters. If <span class="XML-Token">width</span> is less than the number of characters of the value, then the value is padded with spaces to the left.</li>
<li>.Precision:<ul>
<li><b>Integer</b>: Minimum number of displayed digits. Padded with zeros to the left if the value has less digits than specified with <span class="XML-Token">.precision</span>.</li>
<li><b>Floating Point</b>: Number of displayed digits after decimal point. Defaults to <span class="XML-Token">6</span> if not specified.</li>
<li><b>Constant String</b>: Maximum number of displayed characters.</li>
</ul>
</li>
</ul>
</li>
<li>... : Additional function parameters to replace format string specifiers. Each parameter can be a constant string, or an expression that resolves to an unsigned 64-bit integer. A parameter type must match the corresponding specifier type.</li>
</ul>
<p><b>Return Value:</b><br/>
 Always returns <span class="XML-Token">0</span>.</p>
<dl class="section note"><dt>Note</dt><dd>For 32-bit specifiers the <b>Message</b> command must print the lower 32 Bit of a 64 Bit debug access variable.</dd></dl>
</td></tr>
<tr>
<td style="white-space: nowrap"><pre>LoadDebugInfo("file")</pre> </td><td><p class="starttd">Loads DWARF debug information from an application executable.<br/>
 <br/>
 <b>Parameters:</b><br/>
</p>
<ul>
<li>file: A constant string with the path to the executable. The path must be relative to the root folder of the pack and use the format <b>path/name.extension</b>. It must not be an expression and it must be enclosed by quotes.</li>
</ul>
<p><b>Return Value:</b><br/>
 Returns <span class="XML-Token">0</span> after successful debug information load.<br/>
 Returns <span class="XML-Token">1</span> if debug information load failed.</p>
<p class="endtd"></p>
</td></tr>
<tr>
<td colspan="2"><b>Functions for communicating with external tools</b>  </td></tr>
<tr>
<td style="white-space: nowrap"><pre>BufferSet (buffID, buffOffset, count, size, value)</pre> </td><td><p class="starttd">Fill a buffer with a specific value pattern. A new buffer of required size is created if it does not exist. An existing buffer is extended if it is too small.<br/>
 <br/>
 <b>Parameters:</b><br/>
</p>
<ul>
<li>buffID: Numeric buffer ID. Must be a constant number.</li>
<li>buffOffset: First byte in the buffer to start writing the specified <b>value</b> pattern. Must be a multiple of <b>size</b>.</li>
<li>count: Number of <b>size</b> items to write with the specified <b>value</b> pattern.</li>
<li>size: Size of a single item to set. Must be in the range of 1 - 8.</li>
<li>value: Value pattern to set. The <b>size</b> least significant bytes of <b>value</b> are used as value pattern for writing the buffer.</li>
</ul>
<p><b>Return Value:</b><br/>
 Number of written bytes (written bytes * access size).</p>
<p class="endtd"></p>
</td></tr>
<tr>
<td style="white-space: nowrap"><pre>BufferGet (buffID, buffOffset, size)</pre> </td><td><p class="starttd">Get a data item from the buffer.<br/>
 <br/>
 <b>Parameters:</b><br/>
</p>
<ul>
<li>buffID: Numeric buffer ID. Must be a constant number. Function fails if buffer does not exist.</li>
<li>buffOffset: Buffer offset in bytes to get the data item from. Must be a multiple of <b>size</b>.</li>
<li>size: Size of a single item to get. Must be in the range of 1 - 8.</li>
</ul>
<p class="endtd"><b>Return Value:</b><br/>
 Date value of specified size at buffer offset.   </p>
</td></tr>
<tr>
<td style="white-space: nowrap"><pre>BufferSize (buffID)</pre> </td><td><p class="starttd">Get the current size of a data buffer.<br/>
 <br/>
 <b>Parameters:</b><br/>
</p>
<ul>
<li>buffID: Numeric buffer ID. Must be a constant number.</li>
</ul>
<p class="endtd"><b>Return Value:</b><br/>
 Current buffer size in bytes. Return value is <span class="XML-Token">0</span> if a buffer does not exist.   </p>
</td></tr>
<tr>
<td style="white-space: nowrap"><pre>BufferRead (buffID, buffOffset, addr, length, mode)</pre> </td><td><p class="starttd">Read data from target and store in buffer. A new buffer of required size is created if it does not exist. An existing buffer is extended if it is too small.<br/>
 <br/>
 <b>Parameters:</b><br/>
</p>
<ul>
<li>buffID: Numeric buffer ID. Must be a constant number.</li>
<li>buffOffset: First byte in the buffer to store the read data. Must be a multiple of the number of bytes as specified by access size in <b>mode</b>.</li>
<li>addr: Target address to start reading from. Must be a multiple of the number of bytes as specified by access size in <b>mode</b>.</li>
<li>length: Number of bytes to read from target. Must be a multiple of the number of bytes as specified by access size in <b>mode</b>.</li>
<li>mode: The target access mode.<ul>
<li>Bit 0..8: Debug access size. One of 8, 16, 32 and 64. Specified debug access size must be supported by the target hardware. For example a DP register access must always be 32-Bit.</li>
<li>Bit 0: Additionally set this Bit to 1 to increment the target address after each debug read access of the specified size.</li>
<li>Bit 9..63: Reserved</li>
</ul>
</li>
</ul>
<p><b>Return Value:</b><br/>
 Always <span class="XML-Token">0</span>. Function causes fatal error if not successful.</p>
<p class="endtd"><b>Code Example:</b><br/>
 Refer to <a class="el" href="debug_description.html#exttoolexample">Calculating a hash sum</a>   </p>
</td></tr>
<tr>
<td style="white-space: nowrap"><pre>BufferWrite(buffID, buffOffset, addr, length, mode)</pre> </td><td><p class="starttd">Write data from buffer into target.<br/>
 <br/>
 <b>Parameters:</b><br/>
</p>
<ul>
<li>buffID: Numeric buffer ID. Must be a constant number. Function fails if buffer does not exist.</li>
<li>buffOffset: First byte in the buffer to transfer into target. Must be a multiple of the number of bytes as specified by access size in <b>mode</b>.</li>
<li>addr: Target address to start writing to. Must be a multiple of the number of bytes as specified by access size in <b>mode</b>.</li>
<li>length: Number of bytes to write to the target. Must be a multiple of the number of bytes as specified by access size in <b>mode</b>. If size of valid buffer data is less than (<b>buffOffset</b> + <b>length</b>) then the function ends early and returns the number of actually written bytes.</li>
<li>mode: The target access mode.<ul>
<li>Bit 0..8: Debug access size. One of 8, 16, 32 and 64. Specified debug access size must be supported by the target hardware. For example a DP register access must always be 32-Bit.</li>
<li>Bit 0: Additionally set this Bit to <span class="XML-Token">1</span> to increment the target address after each debug write access of the specified size.</li>
<li>Bit 9..63: Reserved</li>
</ul>
</li>
</ul>
<p><b>Return Value:</b><br/>
 Always <span class="XML-Token">0</span>. Function causes fatal error if not successful.</p>
<p class="endtd"><b>Code Example:</b><br/>
 Refer to <a class="el" href="debug_description.html#exttoolexample">Calculating a hash sum</a>   </p>
</td></tr>
<tr>
<td style="white-space: nowrap"><pre>BufferStreamIn (buffID, buffOffset, length, path, mode, timeout)</pre> </td><td><p class="starttd">Stream data from an external source, e.g. a file, into a buffer. A new buffer of required size is created if it does not exist. An existing buffer is extended if it is too small.<br/>
 <br/>
 <b>Parameters:</b><br/>
</p>
<ul>
<li>buffID: Numeric buffer ID. Must be a constant number.</li>
<li>buffOffset: First byte in the buffer to store the received data.</li>
<li>length: Maximum number of bytes to stream in. Use value 0xFFFFFFFFFFFFFFFF to for example read a complete file of unknown size.</li>
<li>path: Constant string value representing the source from which to stream data in. Refer to <a class="el" href="debug_description.html#charactersequence">character sequences</a> for path/file name place holders.</li>
<li>mode: Specifies how to treat the data source in the specified mode.<ul>
<li>Bit 0..3: Format of the data source:<br/>
 <span class="XML-Token">0</span> - Binary File<br/>
 Others - Reserved<br/>
</li>
<li>Bit 4..7: Communication options for data source:<br/>
 Reserved</li>
</ul>
</li>
<li>timeout: Timeout in microseconds. If <span class="XML-Token">0</span>, then synchronously wait for the operation to finish.</li>
</ul>
<p><b>Return Value:</b><br/>
 Number of bytes streamed into buffer. Can be less than <b>length</b> if the data source signals its end.</p>
<p class="endtd"><b>Code Example:</b><br/>
 Refer to <a class="el" href="debug_description.html#exttoolexample">Calculating a hash sum</a>   </p>
</td></tr>
<tr>
<td style="white-space: nowrap"><pre>BufferStreamOut (buffID, buffOffset, length, destPath, destMode, timeout)</pre> </td><td><p class="starttd">Stream data from a buffer to an external data sink, e.g. a file.<br/>
 <br/>
 <b>Parameters:</b><br/>
</p>
<ul>
<li>buffID: Numeric buffer ID. Must be a constant number. Function fails if buffer does not exist.</li>
<li>buffOffset: First byte in the buffer to transfer to the external data sink.</li>
<li>length: Maximum number of bytes to stream out.</li>
<li>path: Constant string value representing the destination to which to stream data to. Refer to <a class="el" href="debug_description.html#charactersequence">character sequences</a> for path/file name place holders.</li>
<li>mode: Specifies how to treat the data source in the specified mode.<ul>
<li>Bit 0..3: Format of the data source:<br/>
 <span class="XML-Token">0</span> - Binary File<br/>
 Others - Reserved<br/>
</li>
<li>Bit 4..7: Communication options for data sink:<br/>
 <span class="XML-Token">0</span> - Overwrite<br/>
 <span class="XML-Token">1</span> - Append<br/>
 Others - Reserved<br/>
</li>
</ul>
</li>
<li>timeout: Timeout in microseconds. If <span class="XML-Token">0</span>, then synchronously wait for the operation to finish.</li>
</ul>
<p><b>Return Value:</b><br/>
 Number of bytes streamed to data sink.</p>
<p class="endtd"><b>Code Example:</b><br/>
 Refer to <a class="el" href="debug_description.html#exttoolexample">Calculating a hash sum</a>   </p>
</td></tr>
<tr>
<td style="white-space: nowrap"><pre>RunApplication (appPath, arguments, workDirectory, timeout)</pre> </td><td><p class="starttd">Run an external application.<br/>
 <br/>
 <b>Parameters:</b><br/>
</p>
<ul>
<li>appPath: Constant string representing the application path. Refer to <a class="el" href="debug_description.html#charactersequence">character sequences</a> for path/file name place holders.</li>
<li>arguments: Constant string with arguments to pass to the command line. Same placeholder <a class="el" href="debug_description.html#charactersequence">character sequences</a> apply as for <b>appPath</b>.</li>
<li>workDirectory: A constant string with the work directory for the command line tool. An empty string means that the work directory is the current project folder. Same placeholder <a class="el" href="debug_description.html#charactersequence">character sequences</a> apply as for <b>appPath</b>.</li>
<li>timeout: Timeout in microseconds</li>
</ul>
<p><b>Return Value:</b><br/>
 Application specific exit code.</p>
<p class="endtd"><b>Code Example:</b><br/>
 Refer to <a class="el" href="debug_description.html#exttoolexample">Calculating a hash sum</a>   </p>
</td></tr>
<tr>
<td style="white-space: nowrap"><pre>FilePathExists(path, timeout)</pre> </td><td><p class="starttd">Check if a path exists. If timeout is other than <span class="XML-Token">0</span> then check the path until it becomes valid or until the timeout has elapsed.<br/>
 <br/>
 <b>Parameters:</b><br/>
</p>
<ul>
<li>path: Constant string with the path to check. Refer to <a class="el" href="debug_description.html#charactersequence">character sequences</a> for path/file name place holders.</li>
<li>timeout: Timeout in microseconds:<br/>
 If <span class="XML-Token">0</span>, then the path is checked and the function immediately returns.<br/>
 If other than <span class="XML-Token">0</span>, check the path until it is valid or until the function times out. If <b>timeout</b> is hit while executing a check and that check ends successfully, then the function returns success.<br/>
</li>
</ul>
<p><b>Return Value:</b><br/>
 <span class="XML-Token">0</span> - Path exists<br/>
 <span class="XML-Token">1</span> - Path not found<br/>
 Others - Reserved<br/>
</p>
<p class="endtd"><b>Code Example:</b><br/>
 Refer to <a class="el" href="debug_description.html#exttoolexample">Calculating a hash sum</a>   </p>
</td></tr>
</table>
<dl class="section note"><dt>Note</dt><dd><ul>
<li>Target memory access functions must perform a debug access of the size indicated by their name. The target system must support debug accesses of this size.</li>
<li>Results of all functions are casted to 64-bit unsigned integer values.</li>
<li>Some target access functions determine the used debug and access port by the current values of the <b>__dp</b> and <b>__ap</b> debug access variables. If a target access requires a different debug or access port than the default ones, it must change these values. This change is held until finishing the sequence the change has occurred in.</li>
</ul>
</dd></dl>
<h2><a class="anchor" id="DebugVars"></a>
Debug access variables</h2>
<p>Debug access variables hold 64-bit unsigned integer values and are used in debug access sequences to query debugger settings and states. They are <b>read-only</b> within a sequence except from a limited set of the <a class="el" href="debug_description.html#PredefinedDebugVars">pre-defined debug access variables</a>. Use the <b>debugvars</b> element to specify additional user-defined debug access variables.</p>
<p><a class="anchor" id="PredefinedDebugVars"></a><b>Table: Pre-defined Debug Access Variables</b><br/>
 A debugger needs to support a set of pre-defined debug access variables. These are described in the following table.</p>
<table  class="cmtable" summary="ExpressionType: Pre-defined Debug Access Variables">
<tr>
<th>Variable </th><th>Access </th><th>Description </th><th>Value=  </th></tr>
<tr>
<td style="white-space: nowrap"><pre>__protocol</pre> </td><td>Read-Only </td><td>Debug protocol selection and parameters for target connection.  </td><td>The following bit map applies:<br/>
<ul>
<li>Bit 0..15: Type<ul>
<li><span class="XML-Token">0</span>: Error<br/>
</li>
<li><span class="XML-Token">1</span>: JTAG<br/>
</li>
<li><span class="XML-Token">2</span>: Serial Wire Debug (SWD)<br/>
</li>
<li><span class="XML-Token">3</span>: CJTAG<br/>
</li>
</ul>
</li>
<li>Bit 16: SWJ-DP</li>
<li>Bit 17..63: Reserved   </li>
</ul>
</td></tr>
<tr>
<td style="white-space: nowrap"><pre>__connection</pre> </td><td>Read-Only </td><td>Target connection configuration.  </td><td>The following bit map applies:<br/>
<ul>
<li>Bit 0..7: Connection type<ul>
<li><span class="XML-Token">0</span>: Error or target is disconnected.</li>
<li><span class="XML-Token">1</span>: Connection for target debug.</li>
<li><span class="XML-Token">2</span>: Connection for downloading application to flash.</li>
</ul>
</li>
<li>Bit 8..15: Reset type<ul>
<li><span class="XML-Token">0</span>: Error.</li>
<li><span class="XML-Token">1</span>: Hardware Reset (debugger reset line).</li>
<li><span class="XML-Token">2</span>: System Reset Request.</li>
<li><span class="XML-Token">3</span>: Processor Reset Request ("Vector Reset").</li>
</ul>
</li>
<li>Bit 16: Connection under Hardware Reset (debugger reset line)</li>
<li>Bit 17: Hardware Reset is executed as a pre-connection reset (only used for debugger calls to <code>ResetHardware</code>)</li>
<li>Bit 18..63: Reserved   </li>
</ul>
</td></tr>
<tr>
<td style="white-space: nowrap"><pre>__dp</pre> </td><td>Read/Write </td><td>Debug Port selected for target accesses.<br/>
 This variable is initialized when entering a pre-defined debug access sequence on a debug event. The initialization value is the <b>__dp</b> as defined for the used <b>debug</b> element.  </td><td>Debug port ID as specified in a <b>debugport</b> element or <span class="XML-Token">0</span> if no <b>debugport</b> element exists.   </td></tr>
<tr>
<td style="white-space: nowrap"><pre>__ap</pre> </td><td>Read/Write </td><td>Access Port selected for target accesses.<br/>
 This variable is initialized when entering a pre-defined debug access sequence on a debug event. The initialization value is the <b>__ap</b> as defined for the used <b>debug</b> element.  </td><td>Access Port index.   </td></tr>
<tr>
<td style="white-space: nowrap"><pre>__traceout</pre> </td><td>Read-Only </td><td>Activated trace outputs (sinks). Additionally holds information on the selected port width if a parallel trace port is enabled.  </td><td style="white-space: nowrap">The following bit map applies:<br/>
<ul>
<li>Bit 0: Serial Wire Output (SWO) Trace enabled.</li>
<li>Bit 1: Parallel Trace Port enabled.</li>
<li>Bit 2: Trace Buffer enabled.</li>
<li>Bit 3..15: Reserved.</li>
<li>Bit 16..21: Selected Parallel Trace Port size.</li>
<li>Bit 22..63: Reserved.   </li>
</ul>
</td></tr>
<tr>
<td style="white-space: nowrap"><pre>__errorcontrol</pre> </td><td>Read/Write </td><td>Control variable for debug access error handling. All of its bit fields are intialized to <span class="XML-Token">0</span> when entering a pre-defined debug access sequence because of a debug event.  </td><td>The following bit map applies:<br/>
<ul>
<li>Bit 0: Skip errors if set to <span class="XML-Token">1</span>. A debugger must continue the sequence execution.</li>
<li>Bit 1..63: Reserved   </li>
</ul>
</td></tr>
<tr>
<td style="white-space: nowrap"><pre>__Result</pre> </td><td>Read/Write </td><td>Sequence result. A debugger sets this variable to <span class="XML-Token">0</span> before it calls a sequence. The sequence implementation sets it to its result.  </td><td>The following values apply:<br/>
<ul>
<li>0: Success</li>
<li>(-1): Error<ul>
<li>Other - reserved.   </li>
</ul>
</li>
</ul>
</td></tr>
<tr>
<td style="white-space: nowrap"><pre>__FlashOp</pre> </td><td>Read-Only </td><td>Type of the currently executed Flash operation. A debugger sets this value to <span class="XML-Token">0</span> if the executed sequence is not part of a Flash operation.  </td><td>The following values apply:<br/>
<ul>
<li>0: No flash operation</li>
<li>1: Erase full chip</li>
<li>2: Erase flash sector</li>
<li>3: Program flash</li>
<li>Other - reserved.   </li>
</ul>
</td></tr>
<tr>
<td style="white-space: nowrap"><pre>__FlashAddr</pre> </td><td>Read-Only </td><td>Start address for the current Flash operation. A debugger sets this value to <span class="XML-Token">0</span> if the executed sequence is not part of a Flash operation.  </td><td>Memory-mapped target address the currently programmed <a class="el" href="pdsc_family_pg.html#element_flashblock">block</a> is visible at.   </td></tr>
<tr>
<td style="white-space: nowrap"><pre>__FlashLen</pre> </td><td>Read-Only </td><td>Flash buffer length for the current flash operation. A debugger sets this value to <span class="XML-Token">0</span> if the executed sequence is not part of a flash operation.  </td><td></td></tr>
<tr>
<td style="white-space: nowrap"><pre>__FlashArg</pre> </td><td>Read-Only </td><td>Argument for the flash operation as specified in <a class="el" href="pdsc_family_pg.html#element_flashblock">block</a>. A debugger sets this value to <span class="XML-Token">0</span> if the executed sequence is not part of a flash operation.  </td><td>The argument encoding is specific to the debug description for the target device.   </td></tr>
</table>
<h2><a class="anchor" id="externalTools"></a>
Using external tools</h2>
<p>Some functionality cannot be implemented by debug sequences, for example checksum/hash calculations or debug authentication. It is supposed to be provided or implemented by external tools or applications. To communicate with external tools, debug sequences currently provide input/output files. To create these files, buffers are used (see below). To run an external application, use the <code>RunApplication</code> function. To check the availability of an external resource (for example a file), use the <code>FilePathExists</code> function.</p>
<p><b>Buffer</b> <b>handling</b> </p>
<p>Buffers are hidden inside the sequence engine. They can be accessed only via the following functions:</p>
<ul>
<li>For direct buffer access (for example for initialization or "memset" operations): <code>BufferSet</code>, <code>BufferGet</code>, and <code>BufferSize</code>.</li>
<li>For interaction with the target's memory: <code>BufferRead</code> and <code>BufferWrite</code>.</li>
<li>For external interaction via file stream: <code>BufferStreamIn</code> and <code>BufferStreamOut</code>.</li>
<li>Buffer sizes are adjusted as per operations. They cannot get smaller during a sequence execution, only larger.</li>
<li>Buffers can internally have a size of '0', causing an error if calling BufferWrite/BufferStreamOut without having previously filled the buffer.</li>
<li>Newly allocated buffer space is filled with 0's, e.g. for an initial call to BufferRead with a buffer offset.</li>
<li>Buffers are only valid within the sequence creating them. When calling for example a "ChildSequence", it does not see buffers from the caller (even when using the same buffer ID). All buffer operations are only valid for buffers of the "ChildSequence".</li>
</ul>
<p><a class="anchor" id="charactersequence"></a><b>Character</b> <b>sequences</b> </p>
<p>For communication with external tools, you sometimes need to specify file names and paths to the files that contain the data to be exchanged. The following character sequences can be used as placeholders:</p>
<ul>
<li><code>$P:</code> Software project path including trailing slash</li>
<li><code>#P:</code> Software project path + project name, e.g. /project_path/project_name</li>
<li><code>$L:</code> Folder path of the main output file of a software project including trailing slash</li>
<li><code>%L:</code> Full path to the main output file of a software project including file ending</li>
<li><code>$S:</code> Path to the device support pack including trailing slash</li>
<li><code>$D:</code> Name of the selected device</li>
</ul>
<dl class="section note"><dt>Note</dt><dd>Characters '$', '#', and '%' must be duplicated to escape them, i.e. if a path contains the '$' character it must be written as '$$'.</dd></dl>
<p><a class="anchor" id="exttoolexample"></a><b>Code Example: Calculating a hash sum</b></p>
<p>The following code example shows how to call an external tool to calculate a hash for an image file.</p>
<div class="fragment"><div class="line">&lt;block&gt;</div>
<div class="line">  __var length     = 0;</div>
<div class="line">  __var exitCode   = 0;</div>
<div class="line">  __var fileExists = 0;</div>
<div class="line">  </div>
<div class="line">  BufferRead     (0, 0, 0x0080C000, 0xE0, (32|1));   <span class="comment">// Implicit allocation of buffer 0</span></div>
<div class="line">  BufferStreamOut(0, 0, 0xE0, <span class="stringliteral">&quot;$P/SAML11_SHA256_BOCOR_input.bin&quot;</span>, 0, 0);</div>
<div class="line">  exitCode   = RunApplication (<span class="stringliteral">&quot;$S/Tools/CalcSHA256.exe&quot;</span>, <span class="stringliteral">&quot;$P/SAML11_SHA256_BOCOR_input.bin --some-SHA256-parameters --out $P/SAML11_SHA256_BOCOR_output.bin&quot;</span>, <span class="stringliteral">&quot;$P&quot;</span>, 10000000);  <span class="comment">// Timeout is 10 seconds</span></div>
<div class="line">&lt;/block&gt;</div>
<div class="line"></div>
<div class="line">&lt;control <span class="keywordflow">if</span>=<span class="stringliteral">&quot;exitCode == 0&quot;</span> info=<span class="stringliteral">&quot;0 means OK&quot;</span>&gt;</div>
<div class="line">  &lt;block&gt;</div>
<div class="line">    fileExists = (FilePathExists(<span class="stringliteral">&quot;$P/SAML11_SHA256_BOCOR_output.bin&quot;</span>, 5000000) == 0);</div>
<div class="line">  &lt;/block&gt;</div>
<div class="line">  &lt;control <span class="keywordflow">if</span>=<span class="stringliteral">&quot;fileExists&quot;</span>&gt;</div>
<div class="line">    &lt;block&gt;</div>
<div class="line">      BufferStreamIn(0, 0xE0, 0x20, <span class="stringliteral">&quot;$P/SAML11_SHA256_BOCOR_output.bin&quot;</span>, 0, 10000000);  <span class="comment">// Append to buffer, timeout 10s</span></div>
<div class="line">      BufferWrite   (0, 0, 0x0080C000, 0x100, (32|1));</div>
<div class="line">    &lt;/block&gt;</div>
<div class="line">  &lt;/control&gt;</div>
<div class="line">&lt;/control&gt;</div>
<div class="line"></div>
<div class="line">&lt;control <span class="keywordflow">if</span>=<span class="stringliteral">&quot;(exitCode != 0) || (fileExists == 0)&quot;</span>&gt;</div>
<div class="line">  &lt;block&gt;</div>
<div class="line">    Message(2, <span class="stringliteral">&quot;Error while creating hashsum. Aborting sequence.&quot;</span>);</div>
<div class="line">  &lt;/block&gt;</div>
<div class="line">&lt;/control&gt;</div>
</div><!-- fragment --> </div></div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="navelem"><a class="el" href="coresight_setup.html">Debug Setup with CMSIS-Pack</a></li>
    <li class="footer">Generated on Wed Jul 10 2019 15:21:01 for CMSIS-Pack Version 1.6.0 by Arm Ltd. All rights reserved.
	<!--
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.6 
	-->
	</li>
  </ul>
</div>
</body>
</html>
